Crypto Algorithm
Interface Declaration
Import Module
Interface Definition
crypto.hashDigest(OBJECT)
Creates a hash digest of the data.
Parameters:
Parameter Name | Type | Required | Description |
data | String/Uint8Array | No | Content to be computed. Either this or uri must be provided. |
uri | String | No | File address to be computed. Either this or data must be provided. |
algo | String | No | Algorithm. Default: SHA256 Options: MD5, SHA1, SHA256, SHA512 |
Return Value:
Type | Description |
String | The computed digest content. |
Example:
crypto.hmacDigest(OBJECT)
Creates a cryptographic HMAC digest.
Parameters:
Parameter Name | Type | Required | Description |
data | String | Yes | Data to be computed. |
algo | String | No | Algorithm. Default: SHA256 Options: MD5, SHA1, SHA256, SHA512 |
key | String | Yes | Key. |
success | Function | No | Success callback. |
fail | Function | No | Failure callback. |
complete | Function | No | Completion callback. |
success Return Value Object:
Parameter | Type | Description |
data | String | Digest. |
Example:
crypto.sign(OBJECT)
Used to generate a signature.
Parameters:
Parameter Name | Type | Required | Description |
data | String/Uint8Array | No | Text to be signed. Either this or uri must be provided. |
uri | String | No | File address to be signed. Either this or data must be provided. |
algo | String | No | Signature algorithm. Default: 'RSA-SHA256' Options: RSA-MD5, RSA-SHA1, RSA-SHA256, RSA-SHA512 |
privateKey | String | Yes | Private key. |
success | Function | No | Success callback. |
fail | Function | No | Failure callback. |
complete | Function | No | Completion callback. |
success Return Value Object:
Parameter | Type | Description |
data | String/Uint8Array | If input is a string, returns a base64-encoded string; otherwise returns Uint8Array; if only uri is provided, defaults to returning string. |
Example:
crypto.verify(OBJECT)
Used to verify a signature.
Parameters:
Parameter Name | Type | Required | Description |
data | String/Uint8Array | No | Text to be verified. Either this or uri must be provided. |
uri | String | No | File address to be verified. Either this or data must be provided. |
algo | String | No | Signature algorithm. Default: 'RSA-SHA256' Options: RSA-MD5, RSA-SHA1, RSA-SHA256, RSA-SHA512 |
signature | String/Uint8Array | Yes | Signature. |
publicKey | String | Yes | Public key. |
success | Function | No | Success callback. |
fail | Function | No | Failure callback. |
complete | Function | No | Completion callback. |
success Return Value Boolean:
Type | Description |
Boolean | Verification result. True if passed, false if not. |
Example:
crypto.encrypt(OBJECT)
Encrypts data.
Parameters:
Parameter Name | Type | Required | Description |
data | String/Uint8Array | Yes | Data to be encrypted. |
algo | String | No | Encryption algorithm. Default: RSA Options: RSA, AES |
key | String | Yes | Key used for encryption, as a base64-encoded string. |
options | Object | No | Encryption parameters. |
success | Function | No | Success callback. |
fail | Function | No | Failure callback. |
complete | Function | No | Completion callback. |
RSA Parameters options:
Parameter Name | Type | Required | Description |
transformation | String | No | Encryption mode and padding for RSA algorithm. Default: "RSA/None/PKCS1Padding" |
AES Parameters options:
Parameter Name | Type | Required | Description |
transformation | String | No | Encryption mode and padding for AES algorithm. Default: "AES/CBC/PKCS7Padding" |
iv | String | No | Initialization vector for AES encryption/decryption, as a base64-encoded string. Default: key value. |
ivOffset | Number | No | Offset for the initialization vector in AES. Default: 0. |
ivLen | Number | No | Byte length of the initialization vector in AES. Default: 16. |
success Return Value Object:
Parameter | Type | Description |
data | String/Uint8Array | If input is a string, returns a base64-encoded string; otherwise returns Uint8Array. |
Example:
crypto.decrypt(OBJECT)
Decrypts data.
Parameters:
Parameter Name | Type | Required | Description |
data | String/Uint8Array | Yes | Data to be decrypted. |
algo | String | No | Decryption algorithm. Default: RSA Options: RSA, AES |
key | String | Yes | Key used for decryption, as a base64-encoded string. |
options | Object | No | Decryption parameters. |
success | Function | No | Success callback. |
fail | Function | No | Failure callback. |
complete | Function | No | Completion callback. |
RSA Parameters options:
Parameter Name | Type | Required | Description |
transformation | String | No | Encryption mode and padding for RSA algorithm. Default: "RSA/None/PKCS1Padding" |
AES Parameters options:
Parameter Name | Type | Required | Description |
transformation | String | No | Encryption mode and padding for AES algorithm. Default: "AES/CBC/PKCS7Padding" |
iv | String | No | Initialization vector for AES encryption/decryption, as a base64-encoded string. Default: key value. |
ivOffset | Number | No | Offset for the initialization vector in AES. Default: 0. |
ivLen | Number | No | Byte length of the initialization vector in AES. Default: 16. |
success Return Value Object:
Parameter | Type | Description |
data | String/Uint8Array | If input is a string, returns a base64-encoded string; otherwise returns Uint8Array. |
Example:
crypto.btoa(STRING)
Creates a base-64 encoded ASCII string from a String object, where each character in the string is treated as a binary data byte.
Parameters:
Type | Required | Description |
String | Yes | Text to be encoded. |
Return Value String:
Type | Description |
String | The encoded result. |
Example:
crypto.atob(STRING)
Decodes a base-64 encoded string.
Parameters:
Type | Required | Description |
String | Yes | Text to be decoded. |
Return Value String:
Type | Description |
String | The decoded result. |
Example:
Support Details
Device Product | Description |
Xiaomi S1 Pro Sports Health Watch | Not supported |
Xiaomi Band 8 Pro | Not supported |
Xiaomi Watch S3 | Supported |
Redmi Watch 4 | Not supported |
Xiaomi Wrist ECG Blood Pressure Monitor | Not supported |
Xiaomi Watch S4 | Supported |
REDMI Watch 5 | Supported |