public void AesGcmEncryptionMatches(string plainText, string key) { var encrypted = CryptographyHelper.EncryptData(SymmetricAlgorithms.AESGCM, Encoding.UTF8.GetBytes(plainText), Encoding.UTF8.GetBytes(key)); var decrypted = CryptographyHelper.DecryptData(SymmetricAlgorithms.AESGCM, encrypted, Encoding.UTF8.GetBytes(key)); Assert.Equal(Encoding.UTF8.GetString(decrypted), plainText); }
public void HashAlgorithmsMatch(HashAlgorithms enumValue) { string toHash = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ"; HashText hash = new HashText { Algorithm = enumValue, Encoding = new InArgument <Encoding>(ExpressionServices.Convert((env) => System.Text.Encoding.Unicode)) }; Dictionary <string, object> arguments = new Dictionary <string, object>(); arguments.Add(nameof(HashText.Input), toHash); WorkflowInvokerTest invoker = new WorkflowInvokerTest(hash); string activityString = (string)invoker.TestActivity(arguments)[nameof(hash.Result)]; byte[] algorithmBytes = CryptographyHelper.HashData(enumValue, Encoding.Unicode.GetBytes(toHash)); Assert.Equal(activityString, BitConverter.ToString(algorithmBytes).Replace("-", string.Empty)); }
public void SymmetricAlgorithmsEncryptionMatches(SymmetricAlgorithms enumValue) { string toProcess = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ"; string key = "{>@#F09\0"; EncryptText symmetricAlgorithm = new EncryptText { Algorithm = enumValue, Encoding = new InArgument <Encoding>(ExpressionServices.Convert((env) => System.Text.Encoding.Unicode)) }; Dictionary <string, object> arguments = new Dictionary <string, object>(); arguments.Add(nameof(EncryptText.Input), toProcess); arguments.Add(nameof(EncryptText.Key), key); WorkflowInvoker invoker = new WorkflowInvoker(symmetricAlgorithm); string activityString = (string)invoker.Invoke(arguments)[nameof(symmetricAlgorithm.Result)]; byte[] algorithmBytes = CryptographyHelper.DecryptData(enumValue, Convert.FromBase64String(activityString), Encoding.Unicode.GetBytes(key)); Assert.Equal(toProcess, Encoding.Unicode.GetString(algorithmBytes)); }
public void KeyedHashAlgorithmsMatch(KeyedHashAlgorithms enumValue) { string toHash = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ"; string key = "{>@#F09\0"; KeyedHashText keyedHash = new KeyedHashText { Algorithm = enumValue, Encoding = new VisualBasicValue <Encoding>(typeof(Encoding).FullName + "." + nameof(Encoding.Unicode)) }; Dictionary <string, object> arguments = new Dictionary <string, object>(); arguments.Add(nameof(KeyedHashText.Input), toHash); arguments.Add(nameof(KeyedHashText.Key), key); WorkflowInvokerTest invoker = new WorkflowInvokerTest(keyedHash); string activityString = (string)invoker.TestActivity(arguments)[nameof(keyedHash.Result)]; byte[] algorithmBytes = CryptographyHelper.HashDataWithKey(enumValue, Encoding.Unicode.GetBytes(toHash), Encoding.Unicode.GetBytes(key)); Assert.Equal(activityString, BitConverter.ToString(algorithmBytes).Replace("-", string.Empty)); }
public void KeyedHashAlgorithmsMatchWithSecureString(KeyedHashAlgorithms enumValue) { string toHash = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ"; SecureString keySecureString = TestingHelper.StringToSecureString("{>@#F09\0"); KeyedHashText keyedHash = new KeyedHashText { Algorithm = enumValue, Encoding = new InArgument <Encoding>(ExpressionServices.Convert((env) => System.Text.Encoding.Unicode)) }; Dictionary <string, object> arguments = new Dictionary <string, object>(); arguments.Add(nameof(KeyedHashText.Input), toHash); arguments.Add(nameof(KeyedHashText.KeySecureString), keySecureString); WorkflowInvoker invoker = new WorkflowInvoker(keyedHash); string activityString = (string)invoker.Invoke(arguments)[nameof(keyedHash.Result)]; byte[] algorithmBytes = CryptographyHelper.HashDataWithKey(enumValue, Encoding.Unicode.GetBytes(toHash), Encoding.Unicode.GetBytes(TestingHelper.SecureStringToString(keySecureString))); Assert.Equal(activityString, BitConverter.ToString(algorithmBytes).Replace("-", string.Empty)); }
public void SymmetricAlgorithmsDecryptionMatches(SymmetricAlgorithms enumValue) { string toProcess = "`~1234567890-=qwertyuiop[]\\ASDFGHJKL:\"ZXCVBNM<>?ăîșțâ"; string key = "{>@#F09\0"; byte[] algorithmBytes = CryptographyHelper.EncryptData(enumValue, Encoding.Unicode.GetBytes(toProcess), Encoding.Unicode.GetBytes(key)); DecryptText symmetricAlgorithm = new DecryptText { Algorithm = enumValue, Encoding = new VisualBasicValue <Encoding>(typeof(Encoding).FullName + "." + nameof(Encoding.Unicode)) }; Dictionary <string, object> arguments = new Dictionary <string, object>(); arguments.Add(nameof(DecryptText.Input), Convert.ToBase64String(algorithmBytes)); arguments.Add(nameof(DecryptText.Key), key); WorkflowInvokerTest invoker = new WorkflowInvokerTest(symmetricAlgorithm); string activityString = (string)invoker.TestActivity(arguments)[nameof(symmetricAlgorithm.Result)]; Assert.Equal(toProcess, activityString); }