public void AESEncryptStringNoKeyIV()
        {
            // Arrange
            CryptographyFactory f = new CryptographyFactory();

            // Act
            byte[] keyBytes;
            byte[] ivBytes;
            byte[] hashBytes = f.Encrypt("Hello world", out keyBytes, out ivBytes);

            string keyBytes64  = Convert.ToBase64String(keyBytes);
            string ivBytes64   = Convert.ToBase64String(ivBytes);
            string hashBytes64 = Convert.ToBase64String(hashBytes);

            //Console.WriteLine("KeyBytes[{0}]", keyBytes64);
            //Console.WriteLine("IVBytes[{0}]", ivBytes64);
            //Console.WriteLine("HashBytes[{0}]", hashBytes64);


            //Assert.Fail();
            // Assert
            //Assert.AreEqual("ZOyIygCyaOW6GjVnihtTFtIS9PNmskdyMlNKiuyjfzw=", result);
            Assert.NotZero(keyBytes64.Length);
            Assert.NotZero(ivBytes64.Length);
            Assert.NotZero(hashBytes64.Length);
        }
        public void AESEncryptStringWithKeyIV()
        {
            // Arrange
            CryptographyFactory f = new CryptographyFactory();

            // Act
            byte[] keyBytes    = Convert.FromBase64String("yfNvMXVJMJXhbgIKtjroQkrYhfXpyjhK0TP5xYdJVPk=");
            byte[] ivBytes     = Convert.FromBase64String("7/T4oOkXvkoORPFLAPg13w==");
            byte[] hashBytes   = f.Encrypt("Hello world", keyBytes, ivBytes);
            string hashBytes64 = Convert.ToBase64String(hashBytes);

            // Assert
            Assert.AreEqual("dnd6ee2g5NlUFTErWNVGng==", hashBytes64);
        }
        public void AESEncryptStringNoKeyIVAsString()
        {
            // Arrange
            CryptographyFactory f = new CryptographyFactory();

            // Act
            string keyBase64;
            string ivBase64;

            byte[] hashBytes   = f.Encrypt("Hello world", out keyBase64, out ivBase64);
            string hashBytes64 = Convert.ToBase64String(hashBytes);

            // Assert
            Assert.NotZero(keyBase64.Length);
            Assert.NotZero(ivBase64.Length);
            Assert.NotZero(hashBytes64.Length);
        }
예제 #4
0
        public void RsaEncryptBytesNoKey()
        {
            // Arrange
            CryptographyFactory f = new CryptographyFactory();

            // Act
            byte[] inputDataBytes = System.Text.Encoding.UTF8.GetBytes("Hello world");
            System.Security.Cryptography.RSAParameters rsaParameters;
            byte[] cipherBytes = f.Encrypt(inputDataBytes, out rsaParameters);

            string resultBase64 = Convert.ToBase64String(cipherBytes);

            Console.WriteLine("Result = [{0}]", resultBase64);
            Console.WriteLine("Params [{0}]", rsaParameters);
            //PrintRsaParameters(rsaParameters);
            rsaParameters.ToConsole();

            // Assert
            Assert.NotNull(resultBase64);
        }
예제 #5
0
        public void RsaEncryptBytesWithKey()
        {
            // Arrange
            CryptographyFactory f = new CryptographyFactory();

            // Act
            byte[] inputDataBytes = System.Text.Encoding.UTF8.GetBytes("Hello world");
            System.Security.Cryptography.RSAParameters rsaParameters = new System.Security.Cryptography.RSAParameters
            {
                Exponent = Convert.FromBase64String("AQAB"),
                Modulus  = Convert.FromBase64String("31BWO1MiwU4cOteyYVbMnfjLa3dqRkpY26LSfqp6gkUBSyW+CBoSKUK/1XmlkiHLhYyjo38dd/zWH4sP6+fiaXfQFsV7dhzyvS023I6hixg6PFl5wy1qkRXp6IVjRfbrd29ebCuHe6AFz3aOiahtmKPKUBwoPvk5Ak7hgxPIEs0=")
            };
            byte[] hashBytes = f.Encrypt(inputDataBytes, rsaParameters);

            string resultBase64 = Convert.ToBase64String(hashBytes);

            Console.WriteLine("Result = [{0}]", resultBase64);

            // Assert
            Assert.NotNull(resultBase64);
        }