i want to Encrypt and Decrypt data in J2ME using AES Algorithm with bouncy castle can any one give me sample code for that
i want to use ECB with PKCS5Padding
Thanks in Advance.
i want to Encrypt and Decrypt data in J2ME using AES Algorithm with bouncy castle can any one give me sample code for that
i want to use ECB with PKCS5Padding
Thanks in Advance.
I'm sure there are examples out there but I haven't found them. Here are a few hints to help you get started. You need to learn how to connect the BC classes together. First, get the bouncycastle source code and be prepared to look at it when you have questions. It's actually very readable so don't be afraid to examine it when the documentation is poor. For example, many classes want an instance of a
CipherParameters
object, but it is rare for the documentation to specify any more detail. However, in the source code it will be obvious as to which implementing classes are expected.Choose one of the AES engines, for example
AESEngine
, as the encryption engine. Next pick a mode; ECB is rarely correct, so for example if you pick CBC mode then create aCBCBlockCipher
object from yourAESEngine
object. Next, use this object to create aPaddedBufferBlockCipher
object. The default constructor uses PKCS7 padding which is identical to the PKCS5 padding you want. Now you need to create an object to hold the key and IV. This is theCipherParameters
interface. You create the object in two steps. First, you create aKeyParameter
object with your key. Next, you create aParametersWithIV
object with yourKeyParameter
object and your IV. This object is supplied to theinit
method of thePaddedBufferBlockCipher
object and then your are ready to go.EDIT
Here is small example: