encrypt()

boolean encrypt(string data, string public_key)

The encrypt function encrypts the given data using the given public_key (see below) and the RSAES-OAEP padding scheme. It returns a Base64-encoded string with the encrypted data.

Example

<flow>
  <template>
  {
    {{$x509certificate := "MIIBIjANBgkqhk…4IAcFS9z4SQIDAQAB" }}
    {{$data := 'my data' }}
    {{$ciphertext := encrypt($data, $x509certificate) }}
  }
  </template>
<flow>

Public Key Format

Public keys are expected to be supplied in PEM format.

They can be provided as part of an X.509 certificate,

-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

or in PKCS #8 syntax:

-----BEGIN PUBLIC KEY-----

-----END PUBLIC KEY-----

For X.509 certificates the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- boundaries may be omitted. They are required, however, if the certificate is stored together with other data, such as the accompanying private key.

See also

Last updated