本文整理汇总了C#中System.Security.Cryptography.DSA类的典型用法代码示例。如果您正苦于以下问题:C# DSA类的具体用法?C# DSA怎么用?C# DSA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DSA类属于System.Security.Cryptography命名空间,在下文中一共展示了DSA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifySignature
internal bool VerifySignature (DSA dsa)
{
if (signatureOID != "1.2.840.10040.4.3")
throw new CryptographicException ("Unsupported hash algorithm: " + signatureOID);
DSASignatureDeformatter v = new DSASignatureDeformatter (dsa);
// only SHA-1 is supported
v.SetHashAlgorithm ("SHA1");
ASN1 sign = new ASN1 (signature);
if ((sign == null) || (sign.Count != 2))
return false;
// parts may be less than 20 bytes (i.e. first bytes were 0x00)
byte[] part1 = sign [0].Value;
byte[] part2 = sign [1].Value;
byte[] sig = new byte [40];
// parts may be less than 20 bytes (i.e. first bytes were 0x00)
// parts may be more than 20 bytes (i.e. first byte > 0x80, negative)
int s1 = System.Math.Max (0, part1.Length - 20);
int e1 = System.Math.Max (0, 20 - part1.Length);
Buffer.BlockCopy (part1, s1, sig, e1, part1.Length - s1);
int s2 = System.Math.Max (0, part2.Length - 20);
int e2 = System.Math.Max (20, 40 - part2.Length);
Buffer.BlockCopy (part2, s2, sig, e2, part2.Length - s2);
return v.VerifySignature (Hash, sig);
}
示例2: DSAKeyValue
public DSAKeyValue (DSA key)
{
dsa = key;
}
示例3: DSASignatureDeformatterTest
public DSASignatureDeformatterTest ()
{
// key generation is VERY long so one time is enough
dsa = DSA.Create ();
rsa = RSA.Create ();
}
示例4: SetKey
public override void SetKey(AsymmetricAlgorithm key)
{
if (key == null)
throw new ArgumentNullException(nameof(key));
_dsaKey = (DSA)key;
}
示例5: DSASignatureFormatter
public DSASignatureFormatter(AsymmetricAlgorithm key) : this()
{
if (key == null)
throw new ArgumentNullException(nameof(key));
_dsaKey = (DSA)key;
}
示例6: SetKey
public override void SetKey(AsymmetricAlgorithm key)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
this._dsaKey = (DSA) key;
}
示例7: DSASignatureDeformatter
public DSASignatureDeformatter(AsymmetricAlgorithm key) : this()
{
if (key == null)
{
throw new ArgumentNullException("key");
}
this._dsaKey = (DSA) key;
}
示例8: SetUp
public void SetUp ()
{
sig = new SignatureDescription();
// key generation is VERY long so one time is enough
if (dsa == null)
dsa = DSA.Create ();
if (rsa == null)
rsa = RSA.Create ();
}
示例9: SetUp
public void SetUp ()
{
if (rsa == null) {
rsa = RSA.Create ();
rsa.ImportParameters (AllTests.GetRsaKey (true));
}
if (dsa == null)
dsa = DSA.Create ();
}
示例10: SetKey
// Set the key to use to compute the signature.
public override void SetKey(AsymmetricAlgorithm key)
{
if(!(key is DSA))
{
throw new CryptographicException
(_("Crypto_NeedsDSA"));
}
keyContainer = (DSA)key;
}
示例11: SetKey
public override void SetKey (AsymmetricAlgorithm key)
{
if (key != null) {
// this will throw a InvalidCastException if this isn't
// a DSA keypair
dsa = (DSA) key;
}
else
throw new ArgumentNullException ("key");
}
示例12: SetUp
public void SetUp ()
{
shaSignature [0] = 0x51;
md5Signature [0] = 0xB4;
if (rsa == null)
rsa = RSA.Create ();
if (dsa == null)
dsa = DSA.Create ();
}
示例13: make_pubkey
/// <summary>
/// Create a public key block from a private key.
/// </summary>
/// <param name="privateKey">The <see cref="DSA" /> PrivateKey.</param>
/// <returns>The <see cref="DSACryptoServiceProvider" /> PublicKey.</returns>
public static DSACryptoServiceProvider make_pubkey(DSA privateKey)
{
var publicKey = new DSACryptoServiceProvider(1024);
publicKey.ImportParameters(privateKey.ExportParameters(false));
if (!publicKey.PublicOnly)
{
publicKey.Dispose();
throw new Exception("PublicKey contains PrivateKey information, cancelling.");
}
return publicKey;
}
示例14: SetKey
public override void SetKey (AsymmetricAlgorithm key)
{
if (key != null) {
// this will throw a InvalidCastException if this isn't
// a DSA keypair
dsa = (DSA) key;
}
#if NET_2_0
else
throw new ArgumentNullException ("key");
#else
// null is accepted in 1.0/1.1
#endif
}
示例15: Encode
static public byte[] Encode (DSA dsa)
{
DSAParameters param = dsa.ExportParameters (true);
return ASN1Convert.FromUnsignedBigInteger (param.X).GetBytes ();
}