2021-08-30 12:39:49 +00:00
|
|
|
/*
|
2023-03-25 06:16:59 +00:00
|
|
|
* Copyright (c) 2020-2023 Huawei Device Co., Ltd.
|
2021-08-30 12:39:49 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-12-11 09:08:03 +00:00
|
|
|
/**
|
|
|
|
* @file
|
2024-01-08 07:25:39 +00:00
|
|
|
* @kit CryptoArchitectureKit
|
2023-12-11 09:08:03 +00:00
|
|
|
*/
|
|
|
|
|
2021-08-30 12:39:49 +00:00
|
|
|
/**
|
2022-03-09 09:39:23 +00:00
|
|
|
* Defines the cipher response.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @typedef CipherResponse
|
|
|
|
* @syscap SystemCapability.Security.Cipher
|
|
|
|
* @since 3
|
2023-12-22 08:29:39 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export interface CipherResponse {
|
|
|
|
/**
|
|
|
|
* response text
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
text: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-09 09:39:23 +00:00
|
|
|
* Defines the rsa cipher options.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @typedef CipherRsaOptions
|
|
|
|
* @syscap SystemCapability.Security.Cipher
|
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export interface CipherRsaOptions {
|
|
|
|
/**
|
|
|
|
* Action type.
|
|
|
|
* The options are as follows:
|
|
|
|
* encrypt: Encrypts data.
|
|
|
|
* decrypt: Decrypts data.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
action: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text content to be encrypted or decrypted.
|
|
|
|
* The text to be encrypted must be a common text and cannot exceed the length calculated based on the formula (keySize/8 - 66).
|
|
|
|
* keySize indicates the key length.
|
|
|
|
* For example, if the key length is 1024 bytes, the text cannot exceed 62 bytes (1024/8 - 66 = 62).
|
|
|
|
* The text content to be decrypted must be a binary value encoded using Base64.
|
|
|
|
* The default format is used for Base64 encoding.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
text: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keys encrypted using RSA.
|
|
|
|
* During encryption, this parameter is a public key.
|
|
|
|
* During decryption, it is a private key.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
key: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RSA algorithm padding.
|
|
|
|
* The default value is RSA/None/OAEPWithSHA256AndMGF1Padding.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { ?string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
transformation?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when data is encrypted or decrypted successfully.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
2023-03-25 01:38:03 +00:00
|
|
|
* @type { function }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
success: (data: CipherResponse) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when data fails to be encrypted or decrypted.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
2023-03-25 01:38:03 +00:00
|
|
|
* @type { function }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
fail: (data: string, code: number) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the execution is completed.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
2023-03-25 01:38:03 +00:00
|
|
|
* @type { function }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
complete: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-09 09:39:23 +00:00
|
|
|
* Defines the aes cipher options.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @typedef CipherAesOptions
|
|
|
|
* @syscap SystemCapability.Security.Cipher
|
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export interface CipherAesOptions {
|
|
|
|
/**
|
|
|
|
* Action type.
|
|
|
|
* The options are as follows:
|
|
|
|
* encrypt: Encrypts data.
|
|
|
|
* decrypt: Decrypts data.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
action: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text content to be encrypted or decrypted.
|
|
|
|
* The text to be encrypted must be a common text.
|
|
|
|
* The text content to be decrypted must be a binary value encoded using Base64.
|
|
|
|
* The default format is used for Base64 encoding.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
text: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Key used for encryption or decryption, which is a character string encrypted using Base64.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
key: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encryption mode and padding of the AES algorithm.
|
|
|
|
* The default value is AES/CBC/PKCS5Padding.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { ?string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
transformation?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initial vector for AES-based encryption and decryption.
|
|
|
|
* The value is a character string encoded using Base64.
|
|
|
|
* The default value is the key value.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { ?string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
iv?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Offset of the initial vector for AES-based encryption and decryption.
|
|
|
|
* The default value is 0.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { ?string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
ivOffset?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Length of the initial vector for AES-based encryption and decryption.
|
|
|
|
* The default value is 16.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @type { ?string }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
ivLen?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when data is encrypted or decrypted successfully.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
2023-03-25 01:38:03 +00:00
|
|
|
* @type { function }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
success: (data: CipherResponse) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when data fails to be encrypted or decrypted.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
2023-03-25 01:38:03 +00:00
|
|
|
* @type { function }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
fail: (data: string, code: number) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the execution is completed.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
2023-03-25 01:38:03 +00:00
|
|
|
* @type { function }
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
2023-12-22 08:29:16 +00:00
|
|
|
* @deprecated since 11
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
complete: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-09 09:39:23 +00:00
|
|
|
* Defines the cipher functions.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2022-03-09 09:39:23 +00:00
|
|
|
* @since 3
|
2022-10-09 06:27:32 +00:00
|
|
|
* @deprecated since 9
|
|
|
|
* @useinstead ohos.security.cryptoFramework.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export default class Cipher {
|
|
|
|
/**
|
|
|
|
* Encrypts or decrypts data using RSA.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @param { CipherRsaOptions } options - RSA options
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
|
|
|
* @deprecated since 9
|
|
|
|
* @useinstead ohos.security.cryptoFramework.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static rsa(options: CipherRsaOptions): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encrypts or decrypts data using AES.
|
2023-03-24 02:32:30 +00:00
|
|
|
*
|
|
|
|
* @param { CipherAesOptions } options - AES options
|
2022-03-09 09:39:23 +00:00
|
|
|
* @syscap SystemCapability.Security.Cipher
|
2023-03-24 02:32:30 +00:00
|
|
|
* @since 3
|
|
|
|
* @deprecated since 9
|
|
|
|
* @useinstead ohos.security.cryptoFramework.Cipher
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static aes(options: CipherAesOptions): void;
|
2023-03-24 02:32:30 +00:00
|
|
|
}
|