crypto.HexStringToByteArray(ConfigurationManager.AppSettings["rmk"]); and crypto.HexStringToByteArray(ConfigurationManager.AppSettings["rmv"]); below, I know how to mimic crypto.HexStringToByteArray but I need to mimic them as seperate calls
public static string Decrypt(string s, ICrypto crypto)
{
string decryptedString;
s = s.Replace(" ", "+");
// Initialize Rijndael cryptography with app settings values
RijndaelManaged rm = new RijndaelManaged();
rm.Key = crypto.HexStringToByteArray(ConfigurationManager.AppSettings["rmk"]);
rm.IV = crypto.HexStringToByteArray(ConfigurationManager.AppSettings["rmv"]);
// Create the decryptor
ICryptoTransform decryptor = rm.CreateDecryptor(rm.Key, rm.IV);
byte[] bytesToDecrypt = Convert.FromBase64String(s);
MemoryStream msDecrypt = new MemoryStream(bytesToDecrypt);
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
try
{
// Read the data out of the crypto stream
byte[] decryptedBytes = new byte[bytesToDecrypt.Length];
int decryptedByteCount = csDecrypt.Read(decryptedBytes, 0, decryptedBytes.Length);
decryptedString = Encoding.UTF8.GetString(decryptedBytes, 0, decryptedByteCount);
}
finally
{
msDecrypt.Close();
csDecrypt.Close();
}
return decryptedString;
}
n8900498
Member
47 Points
69 Posts
Rhino Mock the same method call but as separate results
Nov 28, 2012 04:34 PM|LINK
public static string Decrypt(string s, ICrypto crypto) { string decryptedString; s = s.Replace(" ", "+"); // Initialize Rijndael cryptography with app settings values RijndaelManaged rm = new RijndaelManaged(); rm.Key = crypto.HexStringToByteArray(ConfigurationManager.AppSettings["rmk"]); rm.IV = crypto.HexStringToByteArray(ConfigurationManager.AppSettings["rmv"]); // Create the decryptor ICryptoTransform decryptor = rm.CreateDecryptor(rm.Key, rm.IV); byte[] bytesToDecrypt = Convert.FromBase64String(s); MemoryStream msDecrypt = new MemoryStream(bytesToDecrypt); CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read); try { // Read the data out of the crypto stream byte[] decryptedBytes = new byte[bytesToDecrypt.Length]; int decryptedByteCount = csDecrypt.Read(decryptedBytes, 0, decryptedBytes.Length); decryptedString = Encoding.UTF8.GetString(decryptedBytes, 0, decryptedByteCount); } finally { msDecrypt.Close(); csDecrypt.Close(); } return decryptedString; }