Hi All, How can we encrypt and decrypt the field v...
# suitescript
s
Hi All, How can we encrypt and decrypt the field value in suitescript 2.0? In 1.0, I used nlapiEncrypt API, nlapiDecrypt APIs. I am using crypto.createSecretKey but getting the error messgae 'AN_ERROR_OCCURRED_WHILE_DECRYPT_PASSWORDGUID' .Thanks
b
what does your attempt look like
s
I found the code in suite answer but it seems there is a problem with the guid. var inputString = 'YWJjZGVmZwo='; var guid = 'd64d049843724831b41d496cb4a4fb57'; var key = crypto.createSecretKey({ guid: guid, encoding: encode.Encoding.UTF_8 }); log.debug('guid', guid); log.debug('inputString', inputString); var cipher = crypto.createCipher({ algorithm: crypto.EncryptionAlg.AES, key: key }); cipher.update({ input: inputString }); var cipherout = cipher.final({ outputEncoding: encode.Encoding.HEX });
b
you have to generate your own
s
means guid?
b
correct
s
How can i generate? Can u pls guide?
b
you have 2 choices, Secrets Management or Secret Keys Fields
I heavily advise using secrets management
you will also need to know the difference between a password/passphrase and the key
netsuite's example that uses utf-8 as an encoding is not typical
s
Ok let me try this
thank you
Hi @battk I am using secret managements but getting the same error message. I believe, i am doing something wrong but not sure what
Can you pls give some instructions?
b
did your code change?
if your code didnt change, then I dont think you are inputting a key into netsuite correctly
utf-8 encoding is usually wrong, aes keys do not represent plain text