BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 08-29-2007, 03:27 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default AES 256 Java Implementation?

Please Login to Remove!

Is there anyone that used AES crypto method for BlackBerry or just give me the code for Java SE, cause i need to encrypth an xml file that i use for database for BB Application.Thanks!
Offline  
Old 09-03-2007, 07:34 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there someone that knows something about the problem?
Offline  
Old 09-03-2007, 07:44 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I used a code like these to encrypt some text (content):

Code:
public EncryptFile(String fileName, String content) {
    try {
      FileConnection fconn = (FileConnection) Connector.open(fileName);
      if (!fconn.exists()) {
        fconn.create();
        OutputStream os = fconn.openOutputStream();
        AESKey key = new AESKey(FileOperations.KEY.getBytes("UTF-8"));//get an instance of AESKey with my key
        NoCopyByteArrayOutputStream out = new NoCopyByteArrayOutputStream();
        BlockEncryptor cryptoStream = new BlockEncryptor(new AESEncryptorEngine(key), out);
        cryptoStream.write(content.getBytes("UTF-8"));
        byte[] cipherText = new byte[content.getBytes("UTF-8").length];
        System.arraycopy(out.getByteArray(), 0, cipherText, 0, out.size());
        //cryptoStream.flush();
        //cryptoStream.close();
        os.write(cipherText);
        os.flush();
        os.close();
      }
      fconn.close();
    } catch (CryptoTokenException e) {
      Dialog.alert("Exception: " + e);
    } catch (CryptoUnsupportedOperationException e) {
      Dialog.alert("Exception: " + e);      
    } catch (IOException e) {
      Dialog.alert("The database is corrupted!" + e);
    } catch (Exception e) {
      Dialog.alert("Exception: " + e);
    }
  }
Here I get CryptoIOException (BadPaddingException) that makes me think that the encryption of the String content object or of the KEY is not right or something else...When I comment these rows that throws the exception
//cryptoStream.flush();
//cryptoStream.close();
I realized that the content is encrypted and after that i decrypt the content but the last four or more (depends on the text length) symbols are lost and not encrypted. What is the problem. Here is my Decryption Code:

Code:
public Document readEncryptedInputStream(String fileName) {
    InputStream is = null;
    Document doc = null;
    try {
      fconn = (FileConnection) Connector.open(fileName);
      is = fconn.openInputStream();
      AESKey key = new AESKey(KEY.getBytes("UTF-8"));
      BlockDecryptor cryptoStream = new BlockDecryptor(new AESDecryptorEngine(key), is);
      byte[] content = new byte[(int) fconn.fileSize()];
      cryptoStream.read(content);
      fconn = (FileConnection) Connector.open(INFO_DB_TEMP);
      if (!fconn.exists()) {
        fconn.create();
      }
      fconn.truncate(0);
      OutputStream os = fconn.openOutputStream();
      os.write(content);
      os.close();
      doc = readInputStream(INFO_DB_TEMP);
    } catch (Exception e) {
      Dialog.alert("Exception: " + e);
    }
    return doc;
  }
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Micro SD Storage Board SD TF Card Memory Shield Module SPI For Arduino new
$0.01
Micro SD Storage Board SD TF Card Memory Shield Module SPI For Arduino new pictureNEW ABB PROCONTIC 07 PR 62 R2 PROGRAM MEMORY (EPROM) MODULE
$459.99
NEW ABB PROCONTIC 07 PR 62 R2 PROGRAM MEMORY (EPROM) MODULE pictureBeetle M-II Plus 1750207051 Multi-Functional POS System 4GB Memory DVI USB Black
$129.99
Beetle M-II Plus 1750207051 Multi-Functional POS System 4GB Memory DVI USB Black pictureALERA HT3SAB Adjustable Table,3 Stage,Memory,Black G4493940
$667.52
ALERA HT3SAB Adjustable Table,3 Stage,Memory,Black G4493940 pictureDS3231 Precision RTC Clock Module Memory Module for Arduino for Raspberry Pi DS
$1.61
DS3231 Precision RTC Clock Module Memory Module for Arduino for Raspberry Pi DS picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.