private static void SHA256WithDSA_Sample() { var s = "hello dsa"; Console.WriteLine(s); var keyParameter = DSAKeyGenerator.Generator(); Console.WriteLine("私钥:"); Console.WriteLine(keyParameter.PrivateKey); Console.WriteLine("公钥:"); Console.WriteLine(keyParameter.PublicKey); Console.WriteLine(); var sign = SHA256WithDSA.GenerateSignature(s, AsymmetricKeyUtilities.GetAsymmetricKeyParameterFormAsn1PrivateKey(keyParameter.PrivateKey)); Console.WriteLine($"sign:{sign}"); var verified = SHA256WithDSA.VerifySignature(s, sign, AsymmetricKeyUtilities.GetAsymmetricKeyParameterFormPublicKey(keyParameter.PublicKey)); Console.WriteLine("验证结果:"); Console.WriteLine(verified ? "signature verified" : "signature not verified"); }
private static void SHA1WithDSASample() { var keyParameter = DSAKeyGenerator.Generator(); var sign = SHA1WithDSA.GenerateSignature("hello dsa", RSAUtilities.GetAsymmetricKeyParameterFormAsn1PrivateKey(keyParameter.PrivateKey)); Console.WriteLine($"sign:{sign}"); var verified = SHA1WithDSA.VerifySignature("hello dsa", sign, RSAUtilities.GetAsymmetricKeyParameterFormPublicKey(keyParameter.PublicKey)); Console.WriteLine(verified ? "signature verified" : "signature not verified"); }