I have some data that is encrypted using MACTripleDES in c#, and I need to replicate the same encryption and possibly decryption in ruby. I see there is way in php to do this. see this question, I wonder if there any way I can do the same in ruby. So far I have tried all the des ciphers in openssl, but the results are not matching up. Below is my code snippet in ruby.
['des','des-cbc',
'des-cfb', 'des-ecb', 'des-ede', 'des-ede-cbc', 'des-ede-cfb',
'des-ede-ofb' , 'des-ede3' , 'des-ede3-cbc' , 'des-ede3-cfb' , 'des-ede3-ofb','des-ofb' , 'des3' , 'desx' ].each do |alg|
des = OpenSSL::Cipher::Cipher.new(alg)
des.encrypt
des.padding = 1
des.key = secret_key
update_value = des.update(data)
up_final = update_value + des.final
puts up_final
puts Base64.encode64(up_final).gsub(/\n/, "")
end
And here is c# code snippet,
System.Security.Cryptography.MACTripleDES mac3des = new System.Security.Cryptography.MACTripleDES();
mac3des.Key = my_secret_key;
mac3des.ComputeHash(System.Text.Encoding.UTF8.GetBytes(value));