public void EncryptDecryptStringRoundTripTest() { var encryption = new SymmetricEncryptionService( new SymmetricEncryptionConfiguration() ); var key = encryption.GenerateKeyString(); var iv = encryption.GenerateIvString(); const string inputString = InputStringTest; var encryptedResult = encryption.EncryptString(inputString, key, iv); var decryptedResult = encryption.DecryptString(encryptedResult, key, iv); Assert.AreEqual(inputString, decryptedResult, "Decrypted result is not equal to the original string."); }
public void NoEncryptionTest() { var encryption = new SymmetricEncryptionService( new SymmetricEncryptionConfiguration { AlgorithmType = SymmetricAlgorithmType.None, PlainTextTransform = StringTransform.FromEncoding(Encoding.UTF8), CipherTextTransform = StringTransform.FromEncoding(Encoding.UTF8) } ); const string inputString = InputStringTest; var outputString = encryption.EncryptString(inputString, (string)null, null); Assert.AreEqual(inputString, outputString, "Encrypted string was not equal to the input string."); }
public void NoEncryptionTransformTest() { var encryption = new SymmetricEncryptionService( new SymmetricEncryptionConfiguration { AlgorithmType = SymmetricAlgorithmType.None, PlainTextTransform = StringTransform.FromEncoding(Encoding.UTF8), CipherTextTransform = StringTransform.GetBase64Transform() } ); const string inputString = InputStringTest; var encryptionOutput = encryption.EncryptString(inputString, (string)null, null); var base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(inputString)); Assert.AreEqual(base64String, encryptionOutput, "Encrypted string was not equal to the base64 hash of the input string."); }
public void CustomKeyTransformRoundTripTest() { var encryption = new SymmetricEncryptionService( new SymmetricEncryptionConfiguration { KeyTransform = new CustomKeyStringTransform(), IvTransform = new CustomIvStringTransform() } ); const string key = "Test Key"; const string iv = "Testing IV"; const string inputString = InputStringTest; var encryptedResult = encryption.EncryptString(inputString, key, iv); var decryptedResult = encryption.DecryptString(encryptedResult, key, iv); Assert.AreEqual(inputString, decryptedResult, "Decrypted result is not equal to the original string."); }