public void SymmetricKey_Constructor_SpecifiedProviderSpecifiedKey_ComparePlainText() { //------------------------------------------------------- // arrange //------------------------------------------------------- SymmetricKey key1 = SymmetricKey.Create(Crypto.EncodeModes.TripleDES); SymmetricKey key2 = SymmetricKey.Create(Crypto.EncodeModes.TripleDES, key1.KeyBytes, key1.IVBytes); var plainText = Guid.NewGuid().ToString(); var plainBytes = Encoding.Unicode.GetBytes(plainText); //------------------------------------------------------- // act //------------------------------------------------------- var encoded1 = key1.Encode(plainBytes); var encoded2 = key2.Encode(plainBytes); var decoded1 = key1.Decode(encoded2); var decoded2 = key2.Decode(encoded1); var result1 = CryptoUtils.FromBytes(decoded1, StringFormat.Base64); var result2 = CryptoUtils.FromBytes(decoded2, StringFormat.Base64); //------------------------------------------------------- // assert //------------------------------------------------------- Assert.AreEqual <string>(result1, result2); }
public void SymmetricKey_DefaultConstructor() { //------------------------------------------------------- // arrange //------------------------------------------------------- SymmetricKey key1 = SymmetricKey.Create(); var plainText = Guid.NewGuid().ToString(); var plainBytes = Encoding.Unicode.GetBytes(plainText); //------------------------------------------------------- // act //------------------------------------------------------- var encoded = key1.Encode(plainBytes); var decoded = key1.Decode(encoded); var result = Encoding.Unicode.GetString(decoded); //------------------------------------------------------- // assert //------------------------------------------------------- Assert.AreEqual <string>(plainText, result); }
public void SymmetricKey_NoOperationAfterSerialization() { //------------------------------------------------------- // arrange //------------------------------------------------------- SymmetricKey originalKey = SymmetricKey.Create(); var plainText = Guid.NewGuid().ToString(); var plainBytes = Encoding.Unicode.GetBytes(plainText); //------------------------------------------------------- // act //------------------------------------------------------- var encoded1 = originalKey.Encode(plainBytes); var serializedKey = Serialize.To.DataContract(originalKey); var result = originalKey.Decode(encoded1); //------------------------------------------------------- // assert //------------------------------------------------------- Assert.Fail("Symmetric key should always throw an exception for operations after participating in serializing operations"); }
public void SymmetricKey_Constructor_SpecifiedProvider() { //------------------------------------------------------- // arrange //------------------------------------------------------- SymmetricKey key1 = SymmetricKey.Create(Crypto.EncodeModes.TripleDES); var plainText = Guid.NewGuid().ToString(); var plainBytes = Encoding.Unicode.GetBytes(plainText); //------------------------------------------------------- // act //------------------------------------------------------- var encoded = key1.Encode(plainBytes); var decoded = key1.Decode(encoded); var result = Encoding.Unicode.GetString(decoded); //------------------------------------------------------- // assert //------------------------------------------------------- Assert.AreEqual <string>(plainText, result); }