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

Used 1pc SIEMENS SINUMERIK CPU 810D DRIVE CCU 6FC5447-0AA01-0AA0 Tested Fully
$2228.0
Used 1pc SIEMENS SINUMERIK CPU 810D DRIVE CCU 6FC5447-0AA01-0AA0 Tested Fully picture1PC Used SIEMENS SINUMERIK CPU 810D DRIVE CCU 6FC5 447-0AA01-0AA0 Tested Good
$2228.0
1PC Used SIEMENS SINUMERIK CPU 810D DRIVE CCU 6FC5 447-0AA01-0AA0 Tested Good picture5pcs 25*25*10 MM Aluminum Heat sink for ICs, LED Or CPU Fan DIY Thermal Electric
$0.99
5pcs 25*25*10 MM Aluminum Heat sink for ICs, LED Or CPU Fan DIY Thermal Electric pictureNOTIFIER CPU-5000 CENTRAL PROCESSING SYSTEM FIRE ALARM
$425.0
NOTIFIER CPU-5000 CENTRAL PROCESSING SYSTEM  FIRE ALARM pictureAllen Bradley 1785-LT2 PLC-5/25 Processor Module
$225.0
Allen Bradley 1785-LT2 PLC-5/25 Processor Module picture






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