Join Now
Quality Rating:
  • Currently 3.5 / 5
(3.5 / 5 - 2 votes cast)
Expertise Level:
  • Currently 4.0 / 5
(4.0 / 5 - 2 votes cast)

This page was last modified 19:31, 30 March 2008.

Encryption of data using JSR-177

From Forum Nokia Wiki

Example

A quick example on how to encrypt and decrypt important data with JSR-177 support on MIDP.


byte[] msg = "THIS IS A SECRET MESSAGE".getBytes();
byte[] enMsg = new byte[10000];
byte[] deMsg = new byte[10000];
//create new cipher using DES algorithm
Cipher c = Cipher.getInstance("DES");
//our raw byte[] key - please note that since we use DES algorithm the key must be 8 bytes long
byte[] b = "SECRET!!".getBytes();
//init the cipher to encrypt the data
c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(b,0,b.length,"DES"));
int numBytes = c.doFinal(msg, 0, msg.length, enMsg, 0);
//init the cipher to decrypt the data
c.init(Cipher.DECRYPT_MODE, new SecretKeySpec(b,0,b.length,"DES"));
numBytes = c.doFinal(enMsg, 0, numBytes, deMsg, 0);
String s = new String(deMsg,0,numBytes);

at the end of this code, object s should be equal to "THIS IS A SECRET MESSAGE".

In the above example we used symmetric (algorithm) encryption which means it's the same amount of time needed to encrypt or decrypt unlike a-symmetric algorithm such as RSA.

Related Discussions
Thread Thread Starter Forum Replies Last Post
End-to-end security with WAP 1.2? Nokia_Archive General Browsing 1 2002-05-16 13:03
JSR 179 - developing applications with it Avengola Mobile Java Tools & SDKs 21 2007-10-25 14:08
Data from a file szj2003 Mobile Java General 4 2007-05-22 17:02
encrypting the data praveena Symbian User Interface 1 2005-10-04 10:23
what is the difference of jsr 226 and tinyline? shydisturbedboy Mobile Java General 4 2007-07-26 22:09
 
Powered by MediaWiki