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_JSONfor 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
| Parameter | Required | Type | Description |
|---|---|---|---|
json_keyset | Yes | STRING | A 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_JSONis the inverse of KEYSET_TO_JSON. UseKEYSET_TO_JSONto export a BINARY keyset as a readable JSON string, andKEYSET_FROM_JSONto 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
| Function | Description |
|---|---|
| NEW_KEYSET | Creates a keyset based on the specified algorithm type. |
| ADD_KEY_TO_KEYSET | Adds a key to a keyset and sets it as the master key. |
| KEYSET_TO_JSON | Converts a BINARY keyset into a readable JSON string for inspection. |
| ROTATE_KEYSET | Generates a new key and sets it as the master key. |
| NEW_WRAPPED_KEYSET | Creates a wrapped keyset using a Key Management Service (KMS) customer master key (CMK). |
| ROTATE_WRAPPED_KEYSET | Rotates the key in an encrypted keyset and re-encrypts data with the new key. |
| USE_WRAPPED_KEYSET | Converts a wrapped keyset into a basic keyset for use in encryption or decryption functions. |
| ENHANCED_SYM_ENCRYPT | Encrypts data using a specified keyset. |
| ENHANCED_SYM_DECRYPT | Decrypts data using a specified keyset. |