コード例 #1
0
        public void CanNotDecryptWithIncorrectVector()
        {
            RijndaelSymmetricCrypto encryptor = new RijndaelSymmetricCrypto("password", "rgb init vector.", 8, 8, 256, "verysalty", 3);
            const string startingString = "Batman > Superman";
            string encrypted = encryptor.Encrypt(startingString);

            RijndaelSymmetricCrypto decryptor = new RijndaelSymmetricCrypto("password", "rgb init vector!", 8, 8, 256, "verysalty", 3);
            string decrypted = decryptor.Decrypt(encrypted);
            Assert.AreNotEqual(startingString, decrypted);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RijndaelSymmetricCryptoSerialized"/> class.
 /// </summary>
 /// <param name="configurationFilePath">The configuration file path.</param>
 public RijndaelSymmetricCryptoSerialized(IFilePath configurationFilePath)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(RijndaelSymmetricCryptoConfiguration));
     using (Stream stream = configurationFilePath.GetFileStream())
     using (XmlTextReader reader = new XmlTextReader(stream))
     {
         RijndaelSymmetricCryptoConfiguration configuration = serializer.Deserialize(reader) as RijndaelSymmetricCryptoConfiguration;
         this.wrapped = new RijndaelSymmetricCrypto(configuration);
     }
 }
コード例 #3
0
 public void TestInitialize()
 {
     const int minSaltLength = 8;
     const int maxSaltLength = 8;
     const int passwordIterations = 3;
     const int keySize = 256;
     const string password = "******";
     const string rgbInitVector = "EC`MWcW/XT5clpv{";
     const string saltValue = "mGE}6;bzYvth$mpL";
     this.crypto = new RijndaelSymmetricCrypto(password, rgbInitVector, minSaltLength, maxSaltLength, keySize, saltValue, passwordIterations);
 }
コード例 #4
0
 public void CryptoKeysHaveChanged()
 {
     var token = SessionDataSerializer.Serialize(this.Crypto, this.sessionData);
     RijndaelSymmetricCrypto newCrypto = new RijndaelSymmetricCrypto("password", "rgb init vector.", 8, 8, 256, "notverysalty", 3);
     SessionDataSerializer.Deserialize<SessionData>(newCrypto, token);
 }
コード例 #5
0
 public void EncryptedStringIsNotEqualToInput()
 {
     RijndaelSymmetricCrypto rijndaelEnhanced = new RijndaelSymmetricCrypto("password", "rgb init vector.", 8, 8, 256, "verysalty", 3);
     const string startingString = "Batman > Superman";
     string encrypted = rijndaelEnhanced.Encrypt(startingString);
     Assert.AreNotEqual(startingString, encrypted);
 }
コード例 #6
0
 public void DecryptedStringMatchesStartingString()
 {
     RijndaelSymmetricCrypto rijndaelEnhanced = new RijndaelSymmetricCrypto("password", "rgb init vector.", 8, 8, 256, "verysalty", 3);
     const string startingString = "Batman > Superman";
     string encrypted = rijndaelEnhanced.Encrypt(startingString);
     string decrypted = rijndaelEnhanced.Decrypt(encrypted);
     Assert.AreEqual(startingString, decrypted);
 }
コード例 #7
0
 public void TestGenerateKey()
 {
     RijndaelSymmetricCrypto encryptor = new RijndaelSymmetricCrypto("password", "rgb init vector.", 8, 8, 256, "verysalty", 3);
     encryptor.GenerateKey();
 }
コード例 #8
0
 public void TestEncryptAndDecryptStringToByteArray()
 {
     RijndaelSymmetricCrypto rijndaelEnhanced = new RijndaelSymmetricCrypto("password", "rgb init vector.", 8, 8, 256, "verysalty", 3);
     const string startingString = "Batman > Superman";
     string encryptedString = rijndaelEnhanced.Encrypt(startingString);
     byte[] decrypted = rijndaelEnhanced.DecryptToBytes(encryptedString);
     Assert.AreEqual(startingString, Encoding.Default.GetString(decrypted));
 }
コード例 #9
0
 public void EncryptedStringIsNotNullOrEmpty()
 {
     RijndaelSymmetricCrypto rijndaelEnhanced = new RijndaelSymmetricCrypto("password", "rgb init vector.", 8, 8, 256, "verysalty", 3);
     const string startingString = "Batman > Superman";
     string encrypted = rijndaelEnhanced.Encrypt(startingString);
     Assert.IsFalse(string.IsNullOrEmpty(encrypted));
 }