Exemplo n.º 1
0
        public void BouncyCastleCryptoProviderTest2()
        {
            //TODO: Might be useful to provide seed bytes to SignatureProvider and use that to rountrip?
            byte[] seedBytes = new byte[] { 0x1 };
            //var randomnessGenerator = SecureRandom.GetInstance("SHA1PRNG", false);
            //randomnessGenerator.SetSeed(seedBytes);
            var randomessGenerator = new SecureRandom();

            var keyPairGenerator = new Ed25519KeyPairGenerator();

            keyPairGenerator.Init(new Ed25519KeyGenerationParameters(randomessGenerator));
            var keyPair = keyPairGenerator.GenerateKeyPair();

            var          cryptoProvider = new BouncyCastleCryptoProvider();
            const string Curve          = CryptographyAlgorithmConstants.EdDsa.Curves.Ed25519;
            var          privateKey     = new BouncyCastleEdDsaSecurityKey(keyPair.Private, Curve, cryptoProvider);
            var          publicKey      = new BouncyCastleEdDsaSecurityKey(keyPair.Public, Curve, cryptoProvider);

            const string Algorithm = CryptographyAlgorithmConstants.EdDsa.Algorithm;
            var          privateSignatureProvider = new BouncyCastleEdDsaSignatureProvider(privateKey, Algorithm);
            var          publicSignatureProvider  = new BouncyCastleEdDsaSignatureProvider(publicKey, Algorithm);

            var testBytes       = Encoding.UTF8.GetBytes("test");
            var signedTestBytes = privateSignatureProvider.Sign(testBytes);

            Assert.True(publicSignatureProvider.Verify(testBytes, signedTestBytes));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs BouncyCastleEdDsaWrapper.
 /// </summary>
 /// <param name="signatureProvider">A provider for signatures.</param>
 /// <param name="curve">The type of curve.</param>
 /// <param name="securityKey">The security key containing the key material.</param>
 public BouncyCastleEdDsaWrapper(AsymmetricSignatureProvider signatureProvider, BouncyCastleEdDsaSecurityKey securityKey, string curve) : base(signatureProvider, CryptographyAlgorithmConstants.EdDsa.KeyType, curve)
 {
     SecurityKey = securityKey ?? throw new ArgumentNullException(nameof(securityKey));
 }