system.secrets.encrypt
New in 8.3.1
This function is used in Python Scripting.
Description​
Encrypts supplied data using the Secrets Management system encryption service and returns a JSON object containing the encrypted secret.
Syntax #1​
system.secrets.encrypt(string, [charset])
Parameters​
Type | Parameter | Description |
---|---|---|
String | string | The string data to encrypt. |
String | charset | The charset to use when encrypting. Defaults to UTF-8. [optional] |
Returns​
A PyDictionary containing the encrypted secret or None if the JSON is empty. The PyDictionary includes keys such as ciphertext
, encrypted_key
, iv
, protected
, and tag
.
Scope​
Gateway, Vision Client, Perspective Session
Syntax #2​
system.secrets.encrypt(bytes)
Parameters​
Type | Parameter | Description |
---|---|---|
List | bytes | The byte[] data to encrypt. Use a Java compatible byte array for encrypting bytes. |
Returns​
A PyDictionary containing the encrypted secret or None if the JSON is empty. The PyDictionary includes keys such as ciphertext
, encrypted_key
, iv
, protected
, and tag
.
Scope​
Gateway, Vision Client, Perspective Session
Code Examples​
Syntax #1 Code Snippet
stringText = "someTextToEncrypt"
# Encrypt with UTF-8 charset
# and specify a charset.
encrypted = system.secrets.encrypt(stringText, "UTF-16")
Syntax #2 Code Snippet
# Identify content that needs to be encoded.
stringText = "someTextToEncrypt"
charset = "UTF-8"
# Encode Java/jython compatible bytes for encryption.
# The following are two examples of how to create compatible bytes.
# Option 1: Use Java String
from java.lang import String
j_bytes = String(stringText).getBytes(charset)
# Option 2: Use JArray (Java Arrays in Jython)
j_bytes = jarray.array(stringText.encode(charset), "b")
# Encrypt the byte result from one of the two options above.
encrypted = system.secrets.encrypt(j_bytes)