Encryption in NetSuite Suitescript and decryption in Java application

I need to encrypt a string using SuiteScript, send it to a web service written in Java and decrypt it there.

Using SuiteScript I can encrypt and decrypt without any problem. But when i use the same key in java i get different errors.

var x = "string to be encrypted";
var key = 'EB7CB21AA6FB33D3B1FF14BBE7DB4962';
var encrypted = nlapiEncrypt(x,'aes',key);
var decrypted = nlapiDecrypt(encrypted ,'aes',key);

      

^^ works great ^^

Java code

final String strPassPhrase = "EB7CB21AA6FB33D3B1FF14BBE7DB4962"; //min 24 chars

    SecretKeyFactory factory = SecretKeyFactory.getInstance("DESede");
    SecretKey key = factory.generateSecret(new DESedeKeySpec(strPassPhrase.getBytes()));
    Cipher cipher = Cipher.getInstance("DESede");

    cipher.init(Cipher.DECRYPT_MODE, key);

    String encrypted = "3764b8140ae470bda73f7ebed3c33b0895f70c3497c85f39043345128a4bc3b3";
    String decrypted = new String(cipher.doFinal(DatatypeConverter.parseBase64Binary(encrypted)));
    System.out.println("Text Decryted : " + decrypted);

      

With the above code I am getting the exception javax.crypto.BadPaddingException: Given final block not properly padded

The key was generated using openssl

openssl enc -aes-128-ecb -k mypassphrase -P

      

+3


source to share


2 answers


It looks like you currently need to use the Windows app to decrypt messages if it was encrypted with SuiteScript. See List of luxemper: 35099



A workaround is to use an external javascript library for encryption / decryption. We ended up using OpenJS in javascript, but on the Java side had to make sure the default settings were adjusted to match the settings on the javascript side. Java APIs were more flexible than javascript in this regard.

-1


source


it looks like you are encrypting with AES and decrypting with DES. I think the ciphertext needs to be decrypted using the same symmetric algorithm that you used to encrypt.



+1


source







All Articles