Exemple #1
0
        public void SignData()
        {
            #region Arange

            var keyPairAlive = AsymmetricCryptographyEcc.CreateKeyPair();

            var dataA = Guid.Empty.ToByteArray();

            #endregion

            #region Act

            var signatureA = AsymmetricCryptographyEcc.SignData(keyPairAlive.privateKeyInfo, dataA);
            var signatureB = AsymmetricCryptographyEcc.SignData(keyPairAlive.privateKeyInfo, dataA);

            outputHelper.WriteLine(Convert.ToBase64String(signatureA));
            outputHelper.WriteLine(Convert.ToBase64String(signatureB));
            outputHelper.WriteLine("");
            outputHelper.WriteLine(BitConverter.ToString(signatureA).Replace("-", "").ToLower());
            outputHelper.WriteLine(BitConverter.ToString(signatureB).Replace("-", "").ToLower());

            #endregion

            #region Assert

            // The signature generation algorithm includes the selecting of a cryptographically secure random integer
            // https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm

            signatureA.Should().NotEqual(signatureB);

            #endregion
        }
Exemple #2
0
        public void VerifyData()
        {
            #region Arange

            var keyPairAlive = AsymmetricCryptographyEcc.CreateKeyPair();

            var dataA      = Guid.Empty.ToByteArray();
            var signatureA = AsymmetricCryptographyEcc.SignData(keyPairAlive.privateKeyInfo, dataA);

            #endregion

            #region Act

            var verifyData = AsymmetricCryptographyEcc.VerifyData(keyPairAlive.subjectPublicKeyInfo, dataA, signatureA);

            #endregion

            #region Assert

            verifyData.Should().BeTrue();

            #endregion
        }