Tuesday, October 24, 2017

Encrypt and Decrypt text in Weblogic

Encryption and Decryption in Weblogic

2 Options to Encrypt
1 method for Decryption
Opt 1
. /u01/app/oracle/product/fmw/user_projects/domains/<your domain>/bin/setDomainEnv.sh
java weblogic.security.Encrypt <user name to be encrupted w/o quotes>
. /u01/app/oracle/product/fmw/user_projects/domains/<your domain>/bin/setDomainEnv.sh
Not Applicable; as weblogic.security.Decrypt method in unavailable
Opt2
/u01/app/oracle/product/fmw/wlserver_10.3/common/bin/wlst.sh
wls:/offline> domain="/u01/app/oracle/domains/<your domain>"
wls:/offline> service = weblogic.security.internal.SerializedSystemIni.getEncryptionService(domain)
wls:/offline> encryption = weblogic.security.internal.encryption.ClearOrEncryptedService(service)
wls:/offline> print encryption.encrypt("Welcome1")
{AES}DY2vfJ80wx72i8GUhNYFgiPsxr2ImFBrpOmUYcfMFBo=
/u01/app/oracle/product/fmw/wlserver_10.3/common/bin/wlst.sh
wls:/offline> domain="/u01/app/oracle/domains/<your domain>"
wls:/offline> service = weblogic.security.internal.SerializedSystemIni.getEncryptionService(domain)
wls:/offline> encryption = weblogic.security.internal.encryption.ClearOrEncryptedService(service)
wls:/offline> print encryption.decrypt("{AES}DY2vfJ80wx72i8GUhNYFgiPsxr2ImFBrpOmUYcfMFBo=")
Welcome1


If you are getting error show below, then most likely the encrypted password present in boot.properties has a trailing / in it. 

For example, if the encrypted password is "{AES}7KmECUnp+AwDeuDSvXw4MlvyoQfoR7uGEequQKVW2wE/=", 
then change it to:
"{AES}7KmECUnp+AwDeuDSvXw4MlvyoQfoR7uGEequQKVW2wE="

Traceback (innermost last):
  File "<console>", line 1, in ?
        at weblogic.security.internal.encryption.JSafeEncryptionServiceImpl.decryptBytes(JSafeEncryptionServiceImpl.java:139)
        at weblogic.security.internal.encryption.JSafeEncryptionServiceImpl.decryptString(JSafeEncryptionServiceImpl.java:187)
        at weblogic.security.internal.encryption.ClearOrEncryptedService.decrypt(ClearOrEncryptedService.java:96)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)