Someone could use the SSCrypto Framework for Cocoa to encrypt text and then decrypt it in C # /. NET? Or can someone offer some kind of guidance?
I am sure that my problem is related to the correct setting of cryptography settings, but I am not sure about using Cocoa, so I can’t say what settings are used in the library. However, my attempt to decrypt it looks like md5 hashing, CBC mode, padding with zeros and I have no idea if IV is installed or not ...
My C # code is as follows:
public static string Decrypt( string toDecrypt, string key, bool useHashing )
{
byte[] keyArray;
byte[] toEncryptArray = Convert.FromBase64String( toDecrypt );
if( useHashing )
{
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash( UTF8Encoding.UTF8.GetBytes( key ) );
hashmd5.Clear();
}
else
keyArray = UTF8Encoding.UTF8.GetBytes( key );
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.CBC;
tdes.Padding = PaddingMode.Zeros;
ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock( toEncryptArray, 0, toEncryptArray.Length );
tdes.Clear();
return UTF8Encoding.UTF8.GetString( resultArray );
}
When I run the encryption on the Cocoa side, I get the encrypted text:
UMldOZh8sBnHAbfN6E / 9KfS1VyWAa7RN
but it will not decrypt on the C # side with the same key.
Any help is appreciated, thanks.
Denny