03-14-2012 08:15 AM
Hi There,
I am using the Basic Encryption Tutorial to implement AES encryption in my application.
My problem is that I cannot seem to decrypt it in my C#.NET application. I have two concerns, not sure which is the problem or both are.
1) In the tutorial there is no use of an Initialization Vector. I am using the AesCryptoServiceProvider from .NET that seems to require an IV to decrypt. I have tried setting the IV in .NET to all zeros but the decrypted message is garbage.
2) If I get past the IV problem then .NET complains about bad padding and how it can't be removed. I have tried using the PKCS5 padding in BB and PKCS7 in .NET. I have read they are the same. Maybe they are the same and the IV is upsetting the padding or else they are not the same.
Anyway, has anybody successfully implemented AES with cross compatibility to .NET?
Please note the supported padding enginges in .NET are { ANSIX923, ISO10126, None, PKCS7, Zeros }
Any ideas greatly appreciated. Thanks.
Solved! Go to Solution.
03-14-2012 08:38 AM
Ok, after spending all of yesterday on this I have just come up with a solution ![]()
The problem was a minor overlooked property in my .NET code. In the AesCryptoServiceProvider class there is a property called Mode which needs to be set to CipherMode.ECB for it to be able to decrypt the BlackBerry generated cipher.
Some Notes
Padding seems to default to it but if there is a problem set it to PaddingMode.PKCS7 this is the equivalent to the PKCS5 padding generated by BlackBerry (see PKCS5FormatterEngine)
The AesCryptoServiceProvider insists that it has a valid InitializationVector set for decryption purposes but it does not use it. I am able to decrypt my cipher regardless of what the IV is set to.
I hope I have been clear about my solution here. And also hope it helps somebody else, In my experience with working with .NET and BlackBerry crypto libraries there are many properties on both sides that can make or break the process while they are not documents. I recommend to thoroughly read all API docs of any classes used to discover these properties which will help with troubleshooting.
11-19-2012 10:39 AM
Hi,
i have the same Problem.
Is it possible that you give me a small sample of your solution?
Thanks in advance.
Benjamin
11-19-2012 04:40 PM
Sure why not, but on one condition.. let me know if it works for you ![]()
So first up is generating the AES key on the BlackBerry:
https://gist.github.com/4114147
Then, encrypt data on the BlackBerry using the provided key:
https://gist.github.com/4114053
Finally, decrypt the encrypted message in .NET:
https://gist.github.com/4114090
Let me know if it helps or if you need more help. Please not that this implementation uses CBC mode, which is not very secure. This was for a college project but if you are implementing for a production system you will probably want to use ECB mode.

11-20-2012 03:41 AM
Hi,
many thanks. No It work's. ![]()
This was exactly what I'm searching for.
Thanks
Benjamin.