BlackBerry
Skip Top Navigation
Developers Partners
North America [change region] Products Solutions Purchasing Support
Developers


Basic Encryption and Decryption

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

  1. Download the file
  2. In the IDE, open the BasicCryptoDeveloperLab.jdw workspace
  3. Open the BasicCryptoDeveloperLab.java source file.

Tasks

  1. Complete the implementation of the encrypt method:
    1. Create a new AES symmetric key using keyData.
    2. Create a new EncryptorEngine and FormatterEngine using the newly created key.
    3. Create a BlockEncryptor using the FormatterEngine.
    4. Create a new Digest (SHA-1) and hash the data using the digest.
    5. Encrypt the data and append the hash returning the ciphertext.
  2. Complete the implementation of the decrypt method:
    1. Create a new AES symmetric key using keyData.
    2. Create a new DecryptorEngine and UnformatterEngine using the newly created key.
    3. Create a BlockDecryptor using the UnformatterEngine.
    4. Decrypt the data.
    5. Create a new Digest (SHA-1) and hash the data using the digest.
    6. 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

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

Back to the Developer Lab Main Menu

 
Other Resources
 
     
 Home | Products | Solutions | Purchasing | Support | Developers | Worldwide | News | About Us | Contact Us | Site Map
 Legal | Copyright © 2008 Research In Motion Limited, unless otherwise noted.