Пример #1
0
        public void EncryptDecrypt_R4096_JSON_Test()
        {
            var key       = RSAEncryptionProvider.CreateKey(RSAKeySizeTypes.R4096, RSAKeyTypes.JSON);
            var signature = RSAEncryptionProvider.Encrypt("image", key.PublicKey, keyType: RSAKeyTypes.JSON);
            var origin    = RSAEncryptionProvider.Decrypt(signature, key.PrivateKey, keyType: RSAKeyTypes.JSON);

            Assert.Equal("image", origin);
        }
Пример #2
0
        public void EncryptDecrypt_R1024_XML_Test()
        {
            var key       = RSAEncryptionProvider.CreateKey(RSAKeySizeTypes.R1024);
            var signature = RSAEncryptionProvider.Encrypt("image", key.PublicKey);
            var origin    = RSAEncryptionProvider.Decrypt(signature, key.PrivateKey);

            Assert.Equal("image", origin);
        }
Пример #3
0
        public void EncryptDecrypt_R3072_JSON_Test()
        {
            var key = RSAEncryptionProvider.CreateKey(RSAKeySizeTypes.R3072, RSAKeyTypes.JSON);

#if NET451
            var signature = RSAEncryptionProvider.EncryptByPublicKey("image", key.PublicKey, true, keyType: RSAKeyTypes.JSON);
            var origin    = RSAEncryptionProvider.DecryptByPrivateKey(signature, key.PrivateKey, true, keyType: RSAKeyTypes.JSON);
#else
            var signature = RSAEncryptionProvider.EncryptByPublicKey("image", key.PublicKey, RSAEncryptionPadding.OaepSHA1, keyType: RSAKeyTypes.JSON);
            var origin    = RSAEncryptionProvider.DecryptByPrivateKey(signature, key.PrivateKey, RSAEncryptionPadding.OaepSHA1, keyType: RSAKeyTypes.JSON);
#endif
            Assert.Equal("image", origin);
        }
Пример #4
0
        public void EncryptDecrypt_R2048_XML_Test()
        {
            var key = RSAEncryptionProvider.CreateKey();

#if NET451
            var signature = RSAEncryptionProvider.EncryptByPublicKey("image", key.PublicKey, true);
            var origin    = RSAEncryptionProvider.DecryptByPrivateKey(signature, key.PrivateKey, true);
#else
            var signature = RSAEncryptionProvider.EncryptByPublicKey("image", key.PublicKey, RSAEncryptionPadding.OaepSHA1);
            var origin    = RSAEncryptionProvider.DecryptByPrivateKey(signature, key.PrivateKey, RSAEncryptionPadding.OaepSHA1);
#endif
            Assert.Equal("image", origin);
        }
Пример #5
0
        public void Test_Encrypt()
        {
            var key         = RSAEncryptionProvider.CreateKey();
            var source      = "装逼打脸2018";
            var cliphertext = RSAEncryptionProvider.Encrypt(source, key.PublickKey, outType: OutType.Hex);
            var plaintext   = RSAEncryptionProvider.Decrypt(cliphertext, key.PrivateKey, outType: OutType.Hex);
            var signData    = RSAEncryptionProvider.SignData(source, key.PrivateKey);
            var verifyData  = RSAEncryptionProvider.VerifyData(source, signData, key.PublickKey);

            Output.WriteLine("密文:\n" + cliphertext);
            Output.WriteLine("明文:\n" + plaintext);
            Output.WriteLine("签名:\n" + signData);
            Output.WriteLine("验签:\n" + verifyData);
        }