Skip to main content
Version: 8.3

system.secrets.decrypt

New in 8.3.1

This function is used in Python Scripting.

Description​

Decrypts the given JSON object containing an encrypted secret using the system encryption service. Manage the lifecycle of the returned PyPlaintext by using a with...as statement or by calling the clear() method.

Syntax​

system.secrets.decrypt(json)

Parameters​

TypeParameterDescription
AnyjsonThe JSON object containing the encrypted secret to decrypt.

Returns​

A PyPlaintext instance containing the decrypted secret.

Scope​

Gateway, Vision Client, Perspective Session

PyPlaintext Class​

It is important to remember to clear the PyPlaintext instance after you are done accessing the secret. The preferred way to do so is use the Python with...as statement, as it is an efficient way to manage resource teardown. If the with...as statement is not appropriate for your use-case, you must clear the PyPlaintext instance manually using the clear() method.

  • When using the getSecretAsString() methods, the returned string representing the secret is not cleaned up until garbage collection reclaims the memory.

  • When using the getSecretAsBytes() method, the byte array returned is a direct reference to the bytes stored in the PyPlaintext instance. Therefore the array returned is cleared when the PyPlaintext is cleared. Refer to the Decode Returned Java Compatible Bytes code example below for options on what to do when the pyPlaintext instance is returned with getSecretAsBytes.

Code Examples​

Code Snippet using a with...as Statement
# Decrypt the output from calling system.secrets.encrypt.
with system.secrets.decrypt(encrypted) as pyPlaintext:
# The original secret is returned by calling methods on the returned PyPlaintext object.
byteArray = pyPlaintext.getSecretAsBytes()

# The byteArray returned is a Jython JArray of byte type.
asString = pyPlaintext.getSecretAsString()
asStringCharSet = pyPlainText.getSecretAsString("UTF-8")
Code Snippet using the clear() Method
# Decrypt the output from calling system.secrets.encrypt.
pyPlainText = system.secrets.decrypt(encrypted)

# The original secret is returned by calling methods on the returned PyPlaintext object.
byteArray = pyPlaintext.getSecretAsBytes()

# The byteArray returned is a Jython JArray of byte type.
asString = pyPlaintext.getSecretAsString()
asStringCharSet = pyPlaintext.getSecretAsString("UTF-8")

# When done using PyPlaintext, call the clear() method.
pyPlaintext.clear()
Decode Returned Java Compatible Bytes
# The following two examples show how to decode Java compatible bytes 
# returned from getSecretAsBytes().
byteArray = pyPlaintext.getSecretAsBytes()

# Option 1: Use Java String to decode to a string.
from java.lang import String
stringDecoded = str(String(byteArray, "UTF-8"))

# Options 2: Convert to python byteArray and decode to a string.
pyByte = byteArray(byteArraySecret)
stringDecoded = pyByte.decode("UTF-8")