How To
Summary
Encrypt and Decrypt password within BPM using the Lombardi CipherHelper package
Objective
This article will demonstrate with steps and sample code on how to encrypt and decrypt a string in BPM business processes. Builtin Lombardi library "com.lombardisoftware.utility.CipherHelper" is used for this demonstration.
Environment
IBM Business Process Manager (Process Flows)
Steps
Here is a sample process:
In activity 1 the password will be encrypted using the key provided.
log.info("===============================================================================================================");
var key="12345678";
var password = "odc123"
var ch = Packages.com.lombardisoftware.utility.CipherHelper.createInstance(key);
tw.local.encPassword = ch.encrypt(password); ?
log.info("password:" + password);
log.info("key:" + key);
log.info("encrypted password with key " + tw.local.encPassword );
ch = null;
log.info("===============================================================================================================");
var key="12345678";
var password = "odc123"
var ch = Packages.com.lombardisoftware.utility.CipherHelper.createInstance(key);
tw.local.encPassword = ch.encrypt(password); ?
log.info("password:" + password);
log.info("key:" + key);
log.info("encrypted password with key " + tw.local.encPassword );
ch = null;
log.info("===============================================================================================================");
In activity 2 the encrypted password is decrypted using the same key that is used during encryption.
log.info("===============================================================================================================");
var key="12345678";
var ch = Packages.com.lombardisoftware.utility.CipherHelper.createInstance(key);
try {
var key="12345678";
var ch = Packages.com.lombardisoftware.utility.CipherHelper.createInstance(key);
try {
log.info("decrypt password (encrypted with key[" + key + "]) with key: " + ch.decrypt(tw.local.encPassword));
}catch(err){
log.info(err);
}
log.info("===============================================================================================================");
log.info("===============================================================================================================");
Log output:
[9/26/18 12:38:20:507 EDT] 000001b6 LoggerScripta I?? ===============================================================================================================
[9/26/18 12:38:20:523 EDT] 000001b6 LoggerScripta I?? password:odc123
[9/26/18 12:38:20:523 EDT] 000001b6 LoggerScripta I?? key:12345678
[9/26/18 12:38:20:523 EDT] 000001b6 LoggerScripta I?? encrypted password with key gYakaclGvzBg94JLOW4lQQ==:sD82BICaewo4KiWe/wpkIQ==
[9/26/18 12:38:20:523 EDT] 000001b6 LoggerScripta I?? ===============================================================================================================
[9/26/18 12:38:20:523 EDT] 000001b6 LoggerScripta I?? ===============================================================================================================
[9/26/18 12:38:20:523 EDT] 000001b6 LoggerScripta I?? decrypt password (encrypted with key[12345678[) with key: odc123
[9/26/18 12:38:20:523 EDT] 000001b6 LoggerScripta I?? ===============================================================================================================
If the key does not match the decryption fails with an error
[9/26/18 13:03:42:260 EDT] 000001a6 LoggerScripta I?? ===============================================================================================================
[9/26/18 13:03:42:260 EDT] 000001a6 LoggerScripta I?? JavaException: java.lang.RuntimeException: Unable to decrypt the string
[9/26/18 13:03:42:260 EDT] 000001a6 LoggerScripta I?? ===============================================================================================================
?
[{"Business Unit":{"code":"BU051","label":"N\/A"},"Product":{"code":"SUPPORT","label":"IBM Worldwide Support"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB33","label":"N\/A"}}]
Was this topic helpful?
Document Information
More support for:
IBM Worldwide Support
Software version:
All Versions
Document number:
745061
Modified date:
02 November 2020
UID
ibm10745061