Пример #1
0
        public void AsymmetricCrypto_RsaKeys()
        {
            string privateKey;
            string publicKey;

            try
            {
                privateKey = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024);
                Assert.IsNotNull(privateKey);
                publicKey = AsymmetricCrypto.GetPublicKey(CryptoAlgorithm.RSA, privateKey);
                Assert.IsNotNull(publicKey);
                Assert.IsTrue(privateKey.Length > publicKey.Length);

                AsymmetricCrypto.SaveKey(CryptoAlgorithm.RSA, KeyContainer, null, privateKey);
                Assert.AreEqual(privateKey, AsymmetricCrypto.LoadPrivateKey(CryptoAlgorithm.RSA, KeyContainer, null));
                Assert.AreEqual(publicKey, AsymmetricCrypto.LoadPublicKey(CryptoAlgorithm.RSA, KeyContainer, null));
            }
            finally
            {
                AsymmetricCrypto.DeleteKey(CryptoAlgorithm.RSA, KeyContainer, null);
            }

            AsymmetricCrypto.DeleteKey(CryptoAlgorithm.RSA, KeyContainer, null);
        }