KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to read a Base64-Encoded value from a Database table managed on the Linux side. In that table there is a column called first_name. On the Linux side I can decrypt this easily by using the following command in PHP: $data = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, "patient_fn_salt", base64_decode("H6XmkH+VWvdD88THCliKJjLisGZIBk3CTNvyQMLnhpo="), MCRYPT_MODE_ECB); However I try as much as I can to duplicate this logic on the C# side and all I get is gibberish. My C# code is below, i hope you have some suggestions because I ran out of ideas :( byte [] cipherText = Convert.FromBase64String("H6XmkH+VWvdD88THCliKJjLisGZIBk3CTNvyQMLnhpo="); byte [] key = Encoding.UTF8.GetBytes("patient_fn_salt"); Array.Resize(ref key, 32); byte [] iv = new byte[32]; string fname = Utilities.Decrypt(cipherText, key, iv); public static string Decrypt(byte[] cipherText, byte[] Key, byte[] IV) { // Check arguments. if (cipherText == null || cipherText.Length <= 0) throw new ArgumentNullException("cipherText"); if (Key == null || Key.Length <= 0) throw new ArgumentNullException("Key"); if (IV == null || IV.Length <= 0) throw new ArgumentNullException("Key"); // TDeclare the streams used // to decrypt to an in memory // array of bytes. MemoryStream msDecrypt = null; CryptoStream csDecrypt = null; StreamReader srDecrypt = null; // Declare the AesManaged object // used to decrypt the data. RijndaelManaged rj = new RijndaelManaged(); // Declare the string used to hold // the decrypted text. string plaintext = null; try { // Create an AesManaged object // with the specified key and IV. rj.Mode = CipherMode.ECB; rj.BlockSize = 256; rj.KeySize = 256; rj.Padding = PaddingMode.Zeros; rj.Key = Key; rj.GenerateIV(); //rj.IV = IV; // Create a decrytor to perfor
Tags (comma-separated)
Save Edits
Cancel