Developers
Local Navigation
Exercise
Build an API that will provide basic encryption and decryption using the Cryptography API through the use of a SymmetricKey.
Objectives
- Build how to create a SymmetricKey.
- Build how to use a SymmetricKey for encryption and decryption.
- Build how to use a Digest to provide data integrity.
Setup
- Download the file (ZIP)
- In the IDE, open the BasicCryptoDeveloperLab.jdw workspace
- Open the BasicCryptoDeveloperLab.java source file.
Tasks
- Complete the implementation of the encrypt method:
- Create a new AES symmetric key using keyData.
- Create a new EncryptorEngine and FormatterEngine using the newly created key.
- Create a BlockEncryptor using the FormatterEngine.
- Create a new Digest (SHA-1) and hash the data using the digest.
- Encrypt the data and append the hash returning the ciphertext.
- Complete the implementation of the decrypt method:
- Create a new AES symmetric key using keyData.
- Create a new DecryptorEngine and UnformatterEngine using the newly created key.
- Create a BlockDecryptor using the UnformatterEngine.
- Decrypt the data.
- Create a new Digest (SHA-1) and hash the data using the digest.
- Verify that the hash is correct and return the plaintext.
Note: You are required to import the net_rim_crypto.jar file into your project to access the Cryptography API.
Check Your Work
Download the completed code (ZIP)
Review
In this exercise, you discovered the following things:
- to create a SymmetricKey and use it for encryption and decryption.
- to use a Digest to provide data integrity.
Additional Labs
Go to the next exercise in “Security for BlackBerry Applications”, Advanced features of the cryptography API