Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 3
Registered: ‎03-25-2010
My Device: 9700
My Carrier: Vodacom
Accepted Solution

CryptoSample

Hi,

 

I am new to Blackberry development.  I have the following encrypt / decrypt routines and need to port it to my blackberry project.  Can you please get me started?

Regards

Jaco

/*
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
*/

public String EncryptData(String data, String skey) throws Exception {      
        String encryptedData = "";        
        
        try{
           byte [] bData = data.getBytes();
           String alg = "AES/ECB/NoPadding"; 
           SecretKey key = new SecretKeySpec(skey.getBytes(), alg.replaceFirst("/.*", "")); 
           Cipher cipher = Cipher.getInstance(alg);
           cipher.init(Cipher.ENCRYPT_MODE, key);
           byte[] encoded = cipher.doFinal(bData);          
           encryptedData = bytesToHex(encoded);
        }
        catch(Exception e){
            throw e;
        }
        return encryptedData;
    }
    
public String DecryptData(String hexString, String skey) throws Exception {
        
        String decryptedData = "";
        try{
           byte [] bData =  convToBinary(hexString);
           
           String alg = "AES/ECB/NoPadding";            
           SecretKey key = new SecretKeySpec(skey.getBytes(), alg.replaceFirst("/.*", ""));           
           Cipher cipher = Cipher.getInstance(alg);
           cipher.init(Cipher.DECRYPT_MODE, key);
           byte[] decoded = cipher.doFinal(bData);
           decryptedData = new String(decoded);
        }
        catch(Exception e){
            throw e;
        }
        return decryptedData;
    }

 

 

BlackBerry Development Advisor
Posts: 15,806
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: CryptoSample

I think this is the closest example that we have available.

 

Use Basic Encryption

http://supportforums.blackberry.com/t5/Java-Development/Use-Basic-Encryption/ta-p/445092

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Highlighted
New Contributor
Posts: 3
Registered: ‎03-25-2010
My Device: 9700
My Carrier: Vodacom

Re: CryptoSample

Thank you, I managed to solve the issue

Regards

Jaco