Keymanager3

Service URI - luna://com.webos.service.keymanager3

Provides methods for generation and deletion of keys, encryption and decryption, generation and verification of signature, etc.
These crypto operations are performed by the keymaster trusted application (TA) running under the trusted execution environment (TEE). It is a similar concept to Android's HW keymaster, demonstrating the high-standard key protection technology.

From webOS TV 24, you can use this API for data protection (confidentiality, integrity).

The following is the list of encryption algorithms provided by keymanager3 and their key sizes.

Encryption
(Key type)
PurposeKey sizeRemarks
AESencrypt, decrypt128, 192, 256
RSAsign, verify, encrypt, decrypt1024, 2048, 3072, 4096Generating RSA keys in the TEE has significant impact on the TV's performance.
The size of a key generated using keymanager3 will be 1024 only. To generate keys of other sizes, generate a key in the app first, and import it to keymanager3 to use crypto operations.
EDsign, verify224(P224), 256(P256), 384(P384), 521(P521)The key size is determined by the curve algorithm.
HMACsign, verify64 or biggerThe recommended size is 256 (32 bytes).

Methods

MethodDescriptionSupported in Emulator
generateKeyRequests generation of a key for the encryption algorithm supported by keymanager3. The length and type of the key should be specified.No
importKeyDelivers a key generated outside to the keymanager3 service.
The key is encrypted by keymanager3 and stored and, later, is used for crypto operations supported by keymanager3.
No
exportKey Gets the public key, which is the pair of the requested key.No
removeKeyRequests deletion of a key generated or stored by keymanager3.No
beginSpecifies the crypto operation of keymanager3 to use using the key name and gets a unique handle id required to call the update/finish method later.No
updateDelivers the unique handle id and data acquired by calling the begin method.No
finishDelivers the unique handle id and data acquired by calling the begin method, completes the crypto operation with the data delivered by the update method, and receives the result.No
abortAfter getting the unique handle id by calling the begin method, requests abortion of the corresponding crypto operation. You MUST call this abort method to stop the operation after calling the begin method. By doing so, you can prevent a critical error on a TV device due to insufficient resource.No

generateKey

Description

Enables an app to generate a new key or keypair and store it in the database.
The key generated by this method can be used only by the owner of the key. For example, if app A creates a key using this method, that key can be used only by this app A.
The key name must be unique, which means you cannot generate a key with the existing key name. To generate a key with the existing name, remove that existing key using the removeKey method first.

Parameters

NameRequiredTypeDescription
nameRequiredStringName of a key to generate.
paramsRequiredObject::ParamSetSpecifies the key-associated authorization parameter set.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanIndicates the result of the operation.
  • true: The operation was successful.
  • false: The operation failed.
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method returns errorCode only if it fails.
errorTextOptionalStringerrorText contains the error code if the method fails. The method returns errorText only if it fails.

Error reference

Error codeError textError description
-10001, -10002, -10003, -10004, -10005, -10006, -10007, -10008, -10009, -10010, -10011, -10012, -10016, -10017, -10018See the Error Code Reference for more details.See the Error Code Reference for more details.

Example

Generate an AES key using the generateKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "generateKey",
  parameters: {
    name: "AES256",
    params: {
      type: "AES",
      size: 256,
      mode: ["ECB", "CBC"],
      purpose: ["encrypt", "decrypt"],
      padding: ["PKCS7"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Generate an RSA key using the generateKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "generateKey",
  parameters: {
    name: "RSA1024",
    params: {
      type: "RSA",
      size: 1024,
      purpose: ["sign", "verify"],
      padding: ["PKCS1"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Generate an HMAC key using the generateKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "generateKey",
  parameters: {
    name: "HMAC256",
    params: {
      type: "HMAC",
      size: 256,
      purpose: ["sign", "verify"],
      digest: ["SHA2_256"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Generate an EC key using the generateKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "generateKey",
  parameters: {
    name: "EC256",
    params: {
      type: "EC",
      size: 256,
      purpose: ["sign", "verify"],
      padding: "PKCS1",
      digest: ["SHA2_256"],
      curve: "P256",
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Return Example

Success return

{
  "returnValue": true
}

Failure return when the key already exists

{
  "returnValue": false,
  "errorCode": -10002,
  "errorText": "Key already exists"
}

Failure return when the key size is invalid

{
  "returnValue": false,
  "errorCode": -10003,
  "errorText": "Invalid key size"
}

Failure return when the purpose is invalid

{
  "returnValue": false,
  "errorCode": -10004,
  "errorText": "Invalid purpose"
}

Failure return when the padding is not supported

{
  "returnValue": false,
  "errorCode": -10006,
  "errorText": "Invalid padding"
}

importKey

Description

Enables an app to import a key or key pair and store it in the database.
To import a key pair, just import the private key, then keymanager3 will derive its public key.

Parameters

NameRequiredTypeDescription
nameRequiredStringName of the key to import.
dataRequiredStringBase64-encoded key data that the app wants to import.
  • For AES and HMAC: Base64-encoded binary format
  • For RAS and EC: Base64-encoded PKCS#8 DER format
paramsRequiredObject::ParamSetSpecifies the key associated authorization parameter set.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanIndicates the result of the operation.
  • true: The operation was successful.
  • false: The operation failed.
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method returns errorCode only if it fails.
errorTextOptionalStringerrorText contains the error code if the method fails. The method returns errorText only if it fails.

Error reference

Error codeError textError description
-10001, -10002, -10003, -10004, -10005, -10006, -10007, -10008, -10009, -10010, -10011, -10012, -10016, -10017, -10018See the Error Code Reference for more details.See the Error Code Reference for more details.

Example

Store the existing AES key in the keymanager3 database using the importKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "importKey",
  parameters: {
    name: "AES256",
    data: "JFWOIEJFOIJQOIEJFOIJQOIEJFOQIJFOIQJEFOQIJFE",
    params: {
      type: "AES",
      size: 256,
      mode: ["ECB", "CBC"],
      purpose: ["encrypt", "decrypt"],
      padding: ["PKCS7"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Store the existing RSA key in the keymanager3 database using the importKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "importKey",
  parameters: {
    name: "RSA2048",
    data: base64data,
    params: {
      type: "RSA",
      size: 2048,
      purpose: ["sign", "verify"],
      padding: ["PKCS1"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Store the existing HMAC key in the keymanager3 database using the importKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "importKey",
  parameters: {
    name: "HMAC192",
    data: "AAECAwQFBgcICQoLDA0OD/Dg0MCwoJCA",
    params: {
      type: "HMAC",
      size: 192,
      purpose: ["sign", "verify"],
      digest: ["SHA2_256"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Store the existing EC key in the keymanager3 database using the importKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "importKey",
  data: "MHgCAQAwEAYHKoZIzj0CAQYFK4EEACEEYTBfAgEBBBzdKeUoBI95MlFJ0fJf7Ny0j2KeaTGWueZpkD1boTwDOgAEwB3KS89AOv+OTGRzshsXPX4CpYJcPIrD6A+z2K0pTBJV/DcefaLag3fhNcFH96jEKcDZxHYNWUA=",
  parameters: {
    name: "EC224",
    params: {
      type: "EC",
      size: 224,
      purpose: ["sign", "verify"],
      padding: "PKCS1",
      digest: ["SHA2_256"],
      curve: "P224",
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Return Example

Success return

{
  "returnValue": true
}

Failure return when the key already exists

{
  "returnValue": false,
  "errorCode": -10002,
  "errorText": "Key already exists"
}

Failure return when the key type is invalid

{
  "returnValue": false,
  "errorCode": -10010,
  "errorText": "Invalid key type"
}

Failure return when the key size is invalid

{
  "returnValue": false,
  "errorCode": -10003,
  "errorText": "Invalid key size"
}

Failure return when the purpose is invalid

{
  "returnValue": false,
  "errorCode": -10004,
  "errorText": "Invalid purpose"
}

Failure return when the padding is not supported

{
  "returnValue": false,
  "errorCode": -10006,
  "errorText": "Invalid padding"
}

exportKey

Description

Enables an app to export a public key from the existing keypair by the key name.

Parameters

NameRequiredTypeDescription
nameRequiredStringName of the key from which the app wants to export the public key.
Note
Therefore, only RSA and EC keys can be exported.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanIndicates the result of the operation.
  • true: The operation was successful.
  • false: The operation failed.
pubkeyOptionalStringBase64-encoded DER format of public key.
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method returns errorCode only if it fails.
errorTextOptionalStringerrorText contains the error code if the method fails. The method returns errorText only if it fails.

Error reference

Error codeError textError description
-10001, -20017See the Error Code Reference for more details.See the Error Code Reference for more details.

Example

Get the public key of the existing RSA key using the exportKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "exportKey",
  parameters: {
    name: "RSA1024",
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Get the public key of the existing EC key using the exportKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "exportKey",
  parameters: {
    name: "EC224",
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Return Example

Success return

{
    "returnValue": true,
    "pubkey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwfSdrRlE50jwRsj/WJ8rDpGPaFcMn/1XlKRsRqYUKM/cI4x8DXZjBFtedxJwVRHGzODpyCL7LqyaUU4M9W5seNdnZXtQ2Kfyiq7Bx9QIy5Z1G7eif6ZnG2AN4SruJ+P4vfWBlzu9RyufhwybRoCS08oOS9H
yb+uhrFoh7TiQQRx8zGM2j04pNGuuvyjV0MQNuBL8RjCnoBnQX5PnYonQh4NReIcGH/J3C3XdlnrpuhArYb8wMxzQkOAM91wtMPwU2VX8sYLmdnqDrW+LameghtacuAZUUdJnG4ccanmDj1mPAxpWFx8Q3bxm+OStqt1LnQT5vLc7kgoMyfH70h2dTwIDAQAB"
}

Failure return when the key name does not exist

{
    "returnValue": false,
    "errorCode": -10001,
    "errorText": "Key not found"
}

Failure return when the key type is neither RSA nor EC

{
    "returnValue": false,
    "errorCode": -20017,
    "errorText": "Get error from keymaster"
}

removeKey

Description

Removes a key from the device by key name.

Parameters

NameRequiredTypeDescription
nameRequiredStringName of the key to remove.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanIndicates the result of the operation.
  • true: The operation was successful.
  • false: The operation failed.
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method returns errorCode only if it fails.
errorTextOptionalStringerrorText contains the error code if the method fails. The method returns errorText only if it fails.

Error reference

Error codeError textError description
-10000, -10001, -10009See the Error Code Reference for more details.See the Error Code Reference for more details.

Example

Remove a key using the removeKey method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "removeKey",
  parameters: {
    name: "AES256",
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Return Example

Success return

{
  "returnValue": true
}

Failure return when the key name does not exist

{
    "returnValue": false,
    "errorCode": -10001,
    "errorText": "Key not found"
}

begin

Description

Begins a cryptographic operation, using the specified key, for the specified purpose with the specified parameters (as appropriate), and returns an operation handle that is used with update and finish to complete the operation.

Parameters

NameRequiredTypeDescription
nameRequiredStringName of the key to operate the cryptography.
paramsRequiredObject::ParamSetSpecifies the operation-associated authorization parameter set.
As it is not possible to use a key in any way inconsistent with the authorizations specified at the time of generation, the key owner should list every authorization parameter set that will be used afterward.
  • AES
    • To use AES, "mode" must be set.
    • The default padding is None. PKCS7 is available only for mode ECB or CBC.
    • Except for AES-ECB, if you want to decrypt cipher, the iv value returned from the encrypt operation must be set. (Base64 encoded value, plain length is CBC, CTR -16byte, GCM-12byte)
    • If None is selected as "padding" for AES-ECB or CBC, the size of the input data must be a multiple of the block size.
  • RSA
    • The default padding is PKCS1.
    • The default digest is SHA2_256.
    • Note
      • If "padding" is set to PKCS1_OAEP, "digest" cannot be set as None.
      • If "padding" is set to None, "digest" must be set as None explicitly.
  • EC
    • In the case of the EC algorithm, "curve" is a required param.
    • The default digest is SHA2_256 for EcDsa curve (P224/P256/P384/P521).
  • HMAC
    • The default MAC length is 32 bytes.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanIndicates the result of the operation.
  • true: The operation was successful.
  • false: The operation failed.
handleOptionalStringHandle that is used with the update and finish methods to complete the operation. This handle is the context for the crypto operation.
Note
The actual data type of the handle is uint64, but it returns a handle value as a string.
ivOptionalStringFor AES-CBC/GCM/CTR encryption, if the user does not set the iv value, a unique iv is automatically generated and returned.
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method returns errorCode only if it fails.
errorTextOptionalStringerrorText contains the error code if the method fails. The method returns errorText only if it fails.

Error reference

Error codeError textError description
-10001, -10002, -10003, -10004, -10005, -10006, -10007, -10008, -10009, -10010, -10011, -10012, -10016, -10017, -10018, -20033, -20052See the Error Code Reference for more details.See the Error Code Reference for more details.

Example

Call the begin method for encryption using the AES key

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "begin",
  parameters: {
    name: "AES256",
    params: {
      type: "AES",
      mode: ["CBC"],
      purpose: ["encrypt"],
      padding: ["PKCS7"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
    // Should parse "iv" param
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Call the begin method for decryption using the AES key

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "begin",
  parameters: {
    name: "AES256",
    params: {
      type: "AES",
      size: 256,
      mode: ["CBC"],
      purpose: ["decrypt"],
      padding: ["PKCS7"],
      iv: "tipAtFblvLXf/iLR8t5dGw==",
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Call the begin method for signing using the RSA key

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "begin",
  parameters: {
    name: "RSA1024",
    params: {
      type: "RSA",
      purpose: ["sign"],
      padding: ["PKCS1"],
      digest: ["SHA2_256"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Call the begin method for verification using the RSA key

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "begin",
  parameters: {
    name: "RSA1024",
    params: {
      type: "RSA",
      purpose: ["verify"],
      padding: ["PKCS1"],
      digest: ["SHA2_256"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Call the begin method for signing using the HMAC key

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "begin",
  parameters: {
    name: "HMAC256",
    params: {
      type: "HMAC",
      purpose: ["sign"],
      digest: ["SHA2_256"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Call the begin method for verification using the HMAC key

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "begin",
  parameters: {
    name: "HMAC256",
    params: {
      type: "HMAC",
      purpose: ["verify"],
      digest: ["SHA2_256"],
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Call the begin method for signing using the EC key

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "generateKey",
  parameters: {
    name: "EC256",
    params: {
      type: "EC",
      purpose: ["sign"],
      padding: "PKCS1",
      digest: ["SHA2_512"],
      curve: "P256",
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Call the begin method for verification using the EC key

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "generateKey",
  parameters: {
    name: "EC256",
    params: {
      type: "EC",
      purpose: ["verify"],
      padding: "PKCS1",
      digest: ["SHA2_512"],
      curve: "P256",
    },
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Return Example

Success return

{
  "returnValue": true,
  "handle": "10699227874884526357"
}

Success return with the iv value

{
  "returnValue": true,
  "handle": "10699227874884526357",
  "iv": "tpoUOY8ca/Fd46JGSDKmtw=="
}

Failure return

{
  "returnValue": false,
  "errorCode": -10002,
  "errorText": "Key already exists"
}

Failure return when the key size is invalid

{
  "returnValue": false,
  "errorCode": -10003,
  "errorText": "Invalid key size"
}

Failure return when the purpose is invalid

{
  "returnValue": false,
  "errorCode": -10004,
  "errorText": "Invalid purpose"
}

Failure return when the padding is not supported

{
  "returnValue": false,
  "errorCode": -10006,
  "errorText": "Invalid padding"
}

Failure return when the key type is invalid

{
  "returnValue": false,
  "errorCode": -10010,
  "errorText": "Invalid key type"
}

update

Description

Provides data to process the ongoing operation started by the begin method. If the returned consumed_size is not matched to the full length of the input data, you should call the update method again with the remaining data starting after the data's consumed_size.
Do not process a large amount of data at once. If the data size exceeds 1M, split the data and use theupdate method multiple times with the spilt data sets.

Parameters

NameRequiredTypeDescription
handleRequiredStringOperation handle that is returned by the begin method.
Note
The actual datatype of the handle is uint64, but it is input as a string.
dataRequiredStringInput data to operate.
It must be base64-encoded.
aadOptionalStringaad that is authenticated but not encrypted.
It is only for the AES-GCM block mode, and it must be base64 encoded.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanIndicates the result of the operation.
  • true: The operation was successful.
  • false: The operation failed.
consumed_sizeOptionalStringReturns the consumed size upon the success of the method.
Note
If it is equal to the size of the input, it means all input is delivered. But if not, the app has to call the update method again to deliver the remaining input.
outputOptionalStringReturns the base64-encoded output upon the success of the method.
Note
It could be cipher, plaintext or signature.
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method returns errorCode only if it fails.
errorTextOptionalStringerrorText contains the error code if the method fails. The method returns errorText only if it fails.

Error reference

Error codeError textError description
-10003, -10008, -10009, -10010, -10016, -10017, -20028See the Error Code Reference for more details.See the Error Code Reference for more details.

Example

Call the update method using the handle acquired by calling the begin method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "update",
  parameters: {
    handle: "10699227874884526357",
    data: "dGVzdCB1cGRhdGUgZGF0YQ==",
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Return Example

Success return

{
  "returnValue": true,
  "consumed_size": 16,
  "output": "uvFYV8bL3EByEcswuUOYUg=="
}

Success return

{
  "returnValue": true
}

Failure return when the handle is invalid

{
  "errorCode": -20028,
  "errorText": "Get error from keymaster",
  "returnValue": false
}

finish

Description

Begins a cryptographic operation, using the specified key, for the specified purpose with the specified parameters (as appropriate), and returns an operation handle that is used with update and finish to complete the operation.
Do not process a large amount of data at once. If the data size exceeds 1M, split the data and use thefinish method multiple times with the spilt data sets.

Parameters

NameRequiredTypeDescription
nameRequiredStringName of the key to operate the cryptography.
dataOptionalStringInput data to operate.
It must be base64 encoded.
signatureOptionalStringBase64-encoded signature of the message.
Note
Signature is used for the verification purpose only.
aadOptionalStringaad that is authenticated but not encrypted.
It is only for the AES-GCM block mode, and it must be base64 encoded.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanIndicates the result of the operation.
  • true: The operation was successful.
  • false: The operation failed.
outputOptionalStringBase64-encoded output upon the success of the method.
Note
It could be cipher, plaintext or signature.
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method returns errorCode only if it fails.
errorTextOptionalStringerrorText contains the error code if the method fails. The method returns errorText only if it fails.

Error reference

Error codeError textError description
-10008, -10016, -10017, -20030See the Error Code Reference for more details.See the Error Code Reference for more details.

Example

Call the finish method using the handle acquired by calling the begin method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "finish",
  parameters: {
    handle: "13123551428131904409",
    data: "dGVzdCBmaW5pc2ggZGF0YQ==",
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Call the finish method using the handle acquired by calling the begin method

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "finish",
  parameters: {
    handle: "13123551428131904409",
    data: "dGVzdCBmaW5pc2ggZGF0YQ==",
    signature:
"jUZPi2UrptakGiThbBFQzOKXRGpRP2Jp3v1HJZPE5Y0s+zexj+i8d57rGQ/EoBCwDtJNCgK8wPa9tF7jWjp3mL41P5xszxXzkvOufZ3nME9zj4SbknBNP2Pw16mjOolp1FF0xau5Zpyotm+7D60nu2tJl9tW1j+7Ck+r1OxmDdMdFNbMBJiClwbk3hFU/wtEF1kbN0Z6+XPfkSu5NAs8O83rMWsoJ4iDmeFoF+T2YZlWQLZM6IvN8KNKnkhkVR86RlBeh7Yu8BF3UpA2poVReRuIOLwz8+MLt00+bgiIAPSIBCDg6En0AKZPTLT1gx7PTHwkB05ReyDEJmGNMbslDA==",
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Return Example

Success return when the purpose is encryption/decryption

{
  "returnValue": true,
  "output": "rXXAt28n9kGyNGBK8Ur2fd6eM2FJoPcROwuBMC6l4Cc="
}

Success return when the purpose is signing

{
  "returnValue": true,
  "output": "jUZPi2UrptakGiThbBFQzOKXRGpRP2Jp3v1HJZPE5Y0s+zexj+i8d57rGQ/EoBCwDtJNCgK8wPa9tF7jWjp3mL41P5xszxXzkvOufZ3nME9zj4SbknBNP2Pw16mjOolp1FF0xau5Zpyotm+7D60nu2tJl9tW1j+7Ck+r1OxmDdMdFNbMBJiClwbk3hFU/
wtEF1kbN0Z6+XPfkSu5NAs8O83rMWsoJ4iDmeFoF+T2YZlWQLZM6IvN8KNKnkhkVR86RlBeh7Yu8BF3UpA2poVReRuIOLwz8+MLt00+bgiIAPSIBCDg6En0AKZPTLT1gx7PTHwkB05ReyDEJmGNMbslDA=="
}

Success return when the purpose is verification

{
  "returnValue": true
}

Failure return when verification failed

{
  "errorCode": -20030,
  "errorText": "Get error from keymaster",
  "returnValue": false
}

abort

Description

Aborts the in-progress operation.
Once you call abort with a handle, the handle value is no longer available for cryptographic operation.

Parameters

NameRequiredTypeDescription
handleRequiredStringContext to abort the in-progress operation.
Note
The actual datatype of the handle is uint64, but it is input as a string.

Call returns

NameRequiredTypeDescription
returnValueRequiredBooleanIndicates the result of the operation.
  • true: The operation was successful.
  • false: The operation failed.
errorCodeOptionalNumbererrorCode contains the error code if the method fails. The method returns errorCode only if it fails.
errorTextOptionalStringerrorText contains the error code if the method fails. The method returns errorText only if it fails.

Error reference

Error codeError textError description
-20028See the Error Code Reference for more details.See the Error Code Reference for more details.

Example

If the handle acquired by calling the begin method is no longer needed

var request = webOS.service.request("luna://com.webos.service.keymanager3", {
  method: "abort",
  parameters: {
    handle: "3901299957133494448",
  },
  onSuccess: function (inResponse) {
    console.log("Result: " + JSON.stringify(inResponse));
    // To-Do something
  },
  onFailure: function (inError) {
    console.log("[" + inError.errorCode + "]: " + inError.errorText);
    // To-Do something
  },
});

Return Example

Success return

{
  "returnValue": true
}

Failure return when the handle is not valid

{
  "returnValue": false,
  "errorCode": -20028,
  "errorText": "Get error from keymaster"
}

Objects

ParamSet

Description

Contains the information about the key or operation parameter values.
As it is not possible to use a key in any way inconsistent with the authorizations specified at the time of generation, the key owner should list every authorization parameter set that will be used afterward.

Properties

NameRequiredTypeDescription
typeRequiredStringType of a key.
Possible values are:
  • AES
  • RSA
  • EC
  • HMAC
sizeOptionalNumberSize of a key.
Possible values for each key type are:
  • AES: 128, 192, 256
  • RSA: 1024, 2048, 3072, 4096
    • Only 1024 size can be generated by keymanager3.
    • Apps can import generated RSA-2048/RSA-3072/RSA-4096 key data to keymanager3.
  • EC 224, 256, 384, 521
    • The key size is determined by the curve algorithm. So it is not necessary to specify the size to generate/import EC keys.
    • Supported matching key sizes are: P224(224), P256(256), P384(384), P521(521).
  • HMAC: The minimum size changes according to the digit algorithm. However, the recommended size is at least 256 (32 bytes).
purposeOptionalString arrayPurpose of the operation.
Possible values for each key type are:
  • AES: encrypt, decrypt
  • RSA: sign, verify, encrypt, decrypt
  • EC: sign, verify
  • HMAC: sign, verify
modeOptionalString array
Note
It is applicable only for AES keys. This is required to generate/import/begin with AES keys.
Mode of the operation.
Possible values are:
  • ECB
  • CBC
  • CTR
  • GCM
paddingOptionalString array
Note
It is applicable only for AES keys. This is required to generate/import/begin with AES keys.
Padding mode for the keys.
Possible values are:
  • AES
    • None
    • PKCS7 (Default if "padding" is not specified) (PKCS7 is only for the ECB and CBC modes.)
  • RSA (private key)
    • None
    • PKCS1
    • PKCS1_OAEP (Default if "padding" is not specified)
digestOptionalString arrayDigest of the signing/verification operation.
Possible values for supported key types are:
  • RSA: SHA2_224, SHA2_256, SHA2_384, SHA2_512
  • EC: SHA2_224, SHA2_256, SHA2_384, SHA2_512
  • HMAC: SHA2_256
mac_lengthOptionalStringMAC length for operations that need MAC (HMAC, AES-GCM).
By default, the minimum mac length is as follows:
  • HMAC: 64
  • RSA: 128
You can update the value to a larger value.
ivOptionalString
Note
It is applicable only for AES-CBC, AES-GCM, and AES-CTR keys.
If it is required to use a specific iv value, use this parameter. If not, when using an algorithm that requires an iv value, keymanager3 automatically generates and returns it. The client service that calls the keymanager3 API must manage it.
  • For encryption, if the iv parameter is not set, a unique iv value is automatically generated and returned. (It will be a base64-encoded value, and the plain iv length is CBC, CTR -16byte, or GCM-12byte).
  • For decryption, the iv value used for encryption must be set.
curveOptionalString
Note
It is applicable only for EC keys.
Specify the Elliptic Curve algorithm. This is required to generate/import/begin with EC keys.
Possible values are:
  • P224
  • P256
  • P384
  • P521

Error code reference

Error codeError textError description
-10000not implementedThis feature is not supported.
-10001key not foundThe key could not be found.
-10002key already existsA key with the same name already exists.
-10003invalid key sizeThe selected key size is not supported.
-10004invalid purposeThe selected purpose is not supported.
-10005invalid modeThe selected mode is not supported.
-10006invalid paddingThe selected padding is not supported.
-10007invalid digestThe selected digest is not supported.
-10008invalid data sizeThe data size is too large.
-10009not supported parameterThe data size is too large or does not match the selected algorithm.
-10010Invalid key typeThe selected key type is not supported.
-10011Failed to encrypt keyEncryption of key failed.
-10012Failed to decrypt keyDecryption of key failed.
-10016Base64 encoding is failedBase64 encoding of data failed.
-10017Base64 decoding is failedBase64 decoding of data failed.
-10018Invalid EC curveThe selected EC curve is not supported.
-20009Get error from keymasterThe selected mac length is not supported.
-20010Get error from keymasterThe selected padding mode is not supported.
-20011Get error from keymasterThe selected padding mode is not compatible.
-20012Get error from keymasterThe selected digest mode is not supported.
-20013Get error from keymasterThe selected digest mode is not compatible.
-20017Get error from keymasterUnsupported key type.
-20019Get error from keymasterThe selected key type does not support encryption.
-20020Get error from keymasterThe selected key type does not support verification.
-20021Get error from keymasterThe data size inputted is not valid.
-20028Get error from keymasterThe handle is not valid.
-20030Get error from keymasterVerification failed.
-20033Get error from keymasterKey data is corrupted or invalid.
-20052Get error from keymasterIV value is not set.
No Headings