Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Basic Encryption and Decryption

0 Likes
Started 02-12-2010 by
Modified 09-17-2010 by

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. Open BasicCryptoDeveloperLab_1.zip
  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

 

Check BasicCryptoDeveloperLab_2.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.
Contributors