All Products
Search
Document Center

MaxCompute:KEYSET_FROM_JSON

Last Updated:Mar 26, 2026

Converts a keyset of the JSON type into a keyset of the BINARY type.

Syntax

binary KEYSET_FROM_JSON(string <json_keyset>)

When to use this function

Use KEYSET_FROM_JSON when you need to pass a keyset to an encryption or decryption function such as ENHANCED_SYM_ENCRYPT or ENHANCED_SYM_DECRYPT, but the keyset is currently in JSON format. These functions require a BINARY keyset as input.

Common scenarios:

  • You exported a keyset using KEYSET_TO_JSON for inspection and want to restore it to BINARY for use in encryption operations.

  • You received a keyset in JSON format from an external source and need to use it in MaxCompute.

Parameters

ParameterRequiredTypeDescription
json_keysetYesSTRINGA keyset of the JSON type.

Return value

Returns a keyset of the BINARY type.

Usage notes

  • The BINARY type cannot be displayed directly as readable text. To inspect the output, wrap the result with HEX to convert it to a STRING, or use UNHEX to convert a STRING back to BINARY.

  • KEYSET_FROM_JSON is the inverse of KEYSET_TO_JSON. Use KEYSET_TO_JSON to export a BINARY keyset as a readable JSON string, and KEYSET_FROM_JSON to restore it.

Examples

The following example converts a JSON keyset to a BINARY keyset and uses HEX to display the result as a hex string.

select hex(KEYSET_FROM_JSON('{
    "key": [{
            "description": "hello world",
            "key_id": "r8MqZAEA8PDd3QSL",
            "key_meta_data": {
                "key_material_origin": "Origin_ALIYUN_MAXCOMPUTE",
                "key_material_type": "SYMMETRIC",
                "type": "AES-GCM-256",
                "value": "Jqj7ESbfT1td0DwYDmkZVl13FsuykYFe+1u/MPi++a8="},
            "output_prefix_type": "PREFIX_ALIYUN_MAXCOMPUTE",
            "status": "ENABLED"}],
    "primary_key_id": "r8MqZAEA8PDd3QSL"}')) ;

The following result is returned:

+------------+
| _c0        |
+------------+
| 0A1072384D715A414541385044643351534C12580A330A0B4145532D47434D2D323536122026A8FB1126DF4F5B5DD03C180E6919565D7716CBB291815EFB5BBF30F8BEF9AF1801200210011A1072384D715A414541385044643351534C20022A0B68656C6C6F20776F726C64 |
+------------+

References

FunctionDescription
NEW_KEYSETCreates a keyset based on the specified algorithm type.
ADD_KEY_TO_KEYSETAdds a key to a keyset and sets it as the master key.
KEYSET_TO_JSONConverts a BINARY keyset into a readable JSON string for inspection.
ROTATE_KEYSETGenerates a new key and sets it as the master key.
NEW_WRAPPED_KEYSETCreates a wrapped keyset using a Key Management Service (KMS) customer master key (CMK).
ROTATE_WRAPPED_KEYSETRotates the key in an encrypted keyset and re-encrypts data with the new key.
USE_WRAPPED_KEYSETConverts a wrapped keyset into a basic keyset for use in encryption or decryption functions.
ENHANCED_SYM_ENCRYPTEncrypts data using a specified keyset.
ENHANCED_SYM_DECRYPTDecrypts data using a specified keyset.