View Single Post
  #12 (permalink)  
Old July 3rd, 2013, 06:37 AM
vani rey vani rey is offline
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is my code :
im trying to encrypt AES key with RSA encryption and in this line :
BigInteger exponent_int = new BigInteger(1, exponent);
im getting exception:

private byte[] RSA_Encrypt(byte[] Key) {

try {
byte[] aesKey = Helper.encodeToBase64((Helper.encodeToBase64(Key). getBytes("UTF-8"))).getBytes("UTF-8");

byte[] moduluss = Base64.decode(Constants._DEFAULT_RSA_MODULES);
byte[] exponent = Base64.decode(Constants._DEFAULT_RSA_EXPONENET);
BigInteger exponent_int = new BigInteger(1, exponent);
BigInteger modulus_int = new BigInteger(1, moduluss);

RSAKeyParameters rsapa = new RSAKeyParameters(false, modulus_int, exponent_int);
AsymmetricBlockCipher eng = new RSAEngine();
eng = new PKCS1Encoding(eng);
eng.init(true, rsapa);
byte[] toenc = eng.processBlock(aesKey, 0, aesKey.length);
return toenc;

} catch (NumberFormatException ex) {
System.out.println("\nNumberFormatException : " + ex.getMessage().toString());
} catch (IOException ex) {
System.out.println("\nIOException : " + ex.getMessage().toString());
}catch (InvalidCipherTextException ex) {
System.out.println("\nInvalidCipherTextException : " + ex.getMessage().toString());
}catch (NoClassDefFoundError ex) {
System.out.println("\nNoClassDefFoundError : " + ex.getMessage().toString());
}
return null;
}
Reply With Quote