public void Test_Authenticate()
        {
            var aesCryptoProvider = new AesCryptoProvider
            {
                KeyStore       = _keystore,
                PublicKeyName  = "mypublickey",
                SigningKeyName = "myauthsecret"
            };

            var someText      = "The old grey goose jumped over the wrickety gate.";
            var textBytes     = Encoding.UTF8.GetBytes(someText);
            var encryptedTest = aesCryptoProvider.Encrypt(textBytes, out _iv);

            Assert.NotEqual(encryptedTest, textBytes);

            var hash1 = aesCryptoProvider.GetSignature(encryptedTest);

            var decryptedText = aesCryptoProvider.Decrypt(encryptedTest, _iv, "mypublickey");

            Assert.Equal(decryptedText, textBytes);

            var hash2 = aesCryptoProvider.GetSignature(encryptedTest);

            Assert.Equal(hash1, hash2);
        }
        public void Test_Decrypt2()
        {
            var aesCryptoProvider = new AesCryptoProvider
            {
                KeyStore       = _keystore,
                PublicKeyName  = "mypublickey",
                SigningKeyName = "myauthsecret"
            };

            var message     = "The old grey goose jumped over the wrickety gate.";
            var utf8Message = System.Text.Encoding.UTF8.GetBytes(message);

            byte[] iv;
            var    encryptedBytes = aesCryptoProvider.Encrypt(utf8Message, out iv);
            var    base64message  = Convert.ToBase64String(encryptedBytes);

            _output.WriteLine(base64message);
            _output.WriteLine("iv: " + Convert.ToBase64String(iv));

            var base64MessageBytes = Convert.FromBase64String(base64message);
            var decrypted          = aesCryptoProvider.Decrypt(base64MessageBytes, iv);

            Assert.Equal(message, System.Text.Encoding.UTF8.GetString(decrypted));

            _output.WriteLine("authkey: " + Convert.ToBase64String(Encoding.UTF8.GetBytes(_keystore.GetKey("myauthsecret"))));
            _output.WriteLine("sig: " + Convert.ToBase64String(aesCryptoProvider.GetSignature(encryptedBytes)));
        }
Beispiel #3
0
 public void EncryptTest()
 {
     var target = new AesCryptoProvider() { Key = Key, InitalizationVector = InitializationVector };
     var clearText = "Test";
     var expected = new byte[] { 56, 148, 231, 102, 26, 238, 54, 45, 113, 205, 129, 41, 57, 221, 255, 130 };
     var actual = target.Encrypt(clearText);
     Assert.AreEqual(System.Convert.ToBase64String(expected), System.Convert.ToBase64String(actual));
 }
Beispiel #4
0
        private void btn_aes_encrypt_Click(object sender, EventArgs e)
        {
            byte[]            keyBytes     = getAesKeyBytes();
            string            hexKeyString = keyBytes.Byte2HexString();
            AesCryptoProvider aes          = new AesCryptoProvider(hexKeyString, check_aes_random.Checked);

            aes.CipherMode  = GetAesCipherMode();
            aes.PaddingMode = GetAesPaddingMode();
            var    buff   = aes.Encrypt(GetAesPlainEncoding().GetBytes(txt_aes_plain.Text.Trim()));
            string cihper = GetAesCipherEncode().Encode(buff);

            txt_aes_cipher.Text = cihper;
        }
        public void Test_Encrypt()
        {
            var aesCryptoProvider = new AesCryptoProvider
            {
                KeyStore      = _keystore,
                PublicKeyName = "mypublickey"
            };

            var someText      = "The old grey goose jumped over the wrickety vase.";
            var textBytes     = Encoding.UTF8.GetBytes(someText);
            var encryptedTest = aesCryptoProvider.Encrypt(textBytes, out _iv);

            Assert.NotEqual(encryptedTest, textBytes);
        }
        public void Test_Encrypt2()
        {
            var aesCryptoProvider = new AesCryptoProvider
            {
                KeyStore      = _keystore,
                PublicKeyName = "mypublickey"
            };

            var message     = "The old grey goose jumped over the wrickety gate.";
            var utf8Message = System.Text.Encoding.UTF8.GetBytes(message);

            byte[] iv;
            var    encryptedBytes = aesCryptoProvider.Encrypt(utf8Message, out iv);
            var    base64message  = Convert.ToBase64String(encryptedBytes);
        }