161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (c) 2020-2023 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit CryptoArchitectureKit
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ci/**
2261847f8eSopenharmony_ci * Defines the cipher response.
2361847f8eSopenharmony_ci *
2461847f8eSopenharmony_ci * @typedef CipherResponse
2561847f8eSopenharmony_ci * @syscap SystemCapability.Security.Cipher
2661847f8eSopenharmony_ci * @since 3
2761847f8eSopenharmony_ci * @deprecated since 11
2861847f8eSopenharmony_ci */
2961847f8eSopenharmony_ciexport interface CipherResponse {
3061847f8eSopenharmony_ci  /**
3161847f8eSopenharmony_ci   * response text
3261847f8eSopenharmony_ci   *
3361847f8eSopenharmony_ci   * @type { string }
3461847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
3561847f8eSopenharmony_ci   * @since 3
3661847f8eSopenharmony_ci   * @deprecated since 11
3761847f8eSopenharmony_ci   */
3861847f8eSopenharmony_ci  text: string;
3961847f8eSopenharmony_ci}
4061847f8eSopenharmony_ci
4161847f8eSopenharmony_ci/**
4261847f8eSopenharmony_ci * Defines the rsa cipher options.
4361847f8eSopenharmony_ci *
4461847f8eSopenharmony_ci * @typedef CipherRsaOptions
4561847f8eSopenharmony_ci * @syscap SystemCapability.Security.Cipher
4661847f8eSopenharmony_ci * @since 3
4761847f8eSopenharmony_ci * @deprecated since 11
4861847f8eSopenharmony_ci */
4961847f8eSopenharmony_ciexport interface CipherRsaOptions {
5061847f8eSopenharmony_ci  /**
5161847f8eSopenharmony_ci   * Action type.
5261847f8eSopenharmony_ci   * The options are as follows:
5361847f8eSopenharmony_ci   *   encrypt: Encrypts data.
5461847f8eSopenharmony_ci   *   decrypt: Decrypts data.
5561847f8eSopenharmony_ci   *
5661847f8eSopenharmony_ci   * @type { string }
5761847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
5861847f8eSopenharmony_ci   * @since 3
5961847f8eSopenharmony_ci   * @deprecated since 11
6061847f8eSopenharmony_ci   */
6161847f8eSopenharmony_ci  action: string;
6261847f8eSopenharmony_ci
6361847f8eSopenharmony_ci  /**
6461847f8eSopenharmony_ci   * Text content to be encrypted or decrypted.
6561847f8eSopenharmony_ci   * The text to be encrypted must be a common text and cannot exceed the length calculated based on the formula (keySize/8 - 66).
6661847f8eSopenharmony_ci   * keySize indicates the key length.
6761847f8eSopenharmony_ci   * For example, if the key length is 1024 bytes, the text cannot exceed 62 bytes (1024/8 - 66 = 62).
6861847f8eSopenharmony_ci   * The text content to be decrypted must be a binary value encoded using Base64.
6961847f8eSopenharmony_ci   * The default format is used for Base64 encoding.
7061847f8eSopenharmony_ci   *
7161847f8eSopenharmony_ci   * @type { string }
7261847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
7361847f8eSopenharmony_ci   * @since 3
7461847f8eSopenharmony_ci   * @deprecated since 11
7561847f8eSopenharmony_ci   */
7661847f8eSopenharmony_ci  text: string;
7761847f8eSopenharmony_ci
7861847f8eSopenharmony_ci  /**
7961847f8eSopenharmony_ci   * Keys encrypted using RSA.
8061847f8eSopenharmony_ci   * During encryption, this parameter is a public key.
8161847f8eSopenharmony_ci   * During decryption, it is a private key.
8261847f8eSopenharmony_ci   *
8361847f8eSopenharmony_ci   * @type { string }
8461847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
8561847f8eSopenharmony_ci   * @since 3
8661847f8eSopenharmony_ci   * @deprecated since 11
8761847f8eSopenharmony_ci   */
8861847f8eSopenharmony_ci  key: string;
8961847f8eSopenharmony_ci
9061847f8eSopenharmony_ci  /**
9161847f8eSopenharmony_ci   * RSA algorithm padding.
9261847f8eSopenharmony_ci   * The default value is RSA/None/OAEPWithSHA256AndMGF1Padding.
9361847f8eSopenharmony_ci   *
9461847f8eSopenharmony_ci   * @type { ?string }
9561847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
9661847f8eSopenharmony_ci   * @since 3
9761847f8eSopenharmony_ci   * @deprecated since 11
9861847f8eSopenharmony_ci   */
9961847f8eSopenharmony_ci  transformation?: string;
10061847f8eSopenharmony_ci
10161847f8eSopenharmony_ci  /**
10261847f8eSopenharmony_ci   * Called when data is encrypted or decrypted successfully.
10361847f8eSopenharmony_ci   *
10461847f8eSopenharmony_ci   * @type { function }
10561847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
10661847f8eSopenharmony_ci   * @since 3
10761847f8eSopenharmony_ci   * @deprecated since 11
10861847f8eSopenharmony_ci   */
10961847f8eSopenharmony_ci  success: (data: CipherResponse) => void;
11061847f8eSopenharmony_ci
11161847f8eSopenharmony_ci  /**
11261847f8eSopenharmony_ci   * Called when data fails to be encrypted or decrypted.
11361847f8eSopenharmony_ci   *
11461847f8eSopenharmony_ci   * @type { function }
11561847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
11661847f8eSopenharmony_ci   * @since 3
11761847f8eSopenharmony_ci   * @deprecated since 11
11861847f8eSopenharmony_ci   */
11961847f8eSopenharmony_ci  fail: (data: string, code: number) => void;
12061847f8eSopenharmony_ci
12161847f8eSopenharmony_ci  /**
12261847f8eSopenharmony_ci   * Called when the execution is completed.
12361847f8eSopenharmony_ci   *
12461847f8eSopenharmony_ci   * @type { function }
12561847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
12661847f8eSopenharmony_ci   * @since 3
12761847f8eSopenharmony_ci   * @deprecated since 11
12861847f8eSopenharmony_ci   */
12961847f8eSopenharmony_ci  complete: () => void;
13061847f8eSopenharmony_ci}
13161847f8eSopenharmony_ci
13261847f8eSopenharmony_ci/**
13361847f8eSopenharmony_ci * Defines the aes cipher options.
13461847f8eSopenharmony_ci *
13561847f8eSopenharmony_ci * @typedef CipherAesOptions
13661847f8eSopenharmony_ci * @syscap SystemCapability.Security.Cipher
13761847f8eSopenharmony_ci * @since 3
13861847f8eSopenharmony_ci * @deprecated since 11
13961847f8eSopenharmony_ci */
14061847f8eSopenharmony_ciexport interface CipherAesOptions {
14161847f8eSopenharmony_ci  /**
14261847f8eSopenharmony_ci   * Action type.
14361847f8eSopenharmony_ci   * The options are as follows:
14461847f8eSopenharmony_ci   *   encrypt: Encrypts data.
14561847f8eSopenharmony_ci   *   decrypt: Decrypts data.
14661847f8eSopenharmony_ci   *
14761847f8eSopenharmony_ci   * @type { string }
14861847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
14961847f8eSopenharmony_ci   * @since 3
15061847f8eSopenharmony_ci   * @deprecated since 11
15161847f8eSopenharmony_ci   */
15261847f8eSopenharmony_ci  action: string;
15361847f8eSopenharmony_ci
15461847f8eSopenharmony_ci  /**
15561847f8eSopenharmony_ci   * Text content to be encrypted or decrypted.
15661847f8eSopenharmony_ci   * The text to be encrypted must be a common text.
15761847f8eSopenharmony_ci   * The text content to be decrypted must be a binary value encoded using Base64.
15861847f8eSopenharmony_ci   * The default format is used for Base64 encoding.
15961847f8eSopenharmony_ci   *
16061847f8eSopenharmony_ci   * @type { string }
16161847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
16261847f8eSopenharmony_ci   * @since 3
16361847f8eSopenharmony_ci   * @deprecated since 11
16461847f8eSopenharmony_ci   */
16561847f8eSopenharmony_ci  text: string;
16661847f8eSopenharmony_ci
16761847f8eSopenharmony_ci  /**
16861847f8eSopenharmony_ci   * Key used for encryption or decryption, which is a character string encrypted using Base64.
16961847f8eSopenharmony_ci   *
17061847f8eSopenharmony_ci   * @type { string }
17161847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
17261847f8eSopenharmony_ci   * @since 3
17361847f8eSopenharmony_ci   * @deprecated since 11
17461847f8eSopenharmony_ci   */
17561847f8eSopenharmony_ci  key: string;
17661847f8eSopenharmony_ci
17761847f8eSopenharmony_ci  /**
17861847f8eSopenharmony_ci   * Encryption mode and padding of the AES algorithm.
17961847f8eSopenharmony_ci   * The default value is AES/CBC/PKCS5Padding.
18061847f8eSopenharmony_ci   *
18161847f8eSopenharmony_ci   * @type { ?string }
18261847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
18361847f8eSopenharmony_ci   * @since 3
18461847f8eSopenharmony_ci   * @deprecated since 11
18561847f8eSopenharmony_ci   */
18661847f8eSopenharmony_ci  transformation?: string;
18761847f8eSopenharmony_ci
18861847f8eSopenharmony_ci  /**
18961847f8eSopenharmony_ci   * Initial vector for AES-based encryption and decryption.
19061847f8eSopenharmony_ci   * The value is a character string encoded using Base64.
19161847f8eSopenharmony_ci   * The default value is the key value.
19261847f8eSopenharmony_ci   *
19361847f8eSopenharmony_ci   * @type { ?string }
19461847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
19561847f8eSopenharmony_ci   * @since 3
19661847f8eSopenharmony_ci   * @deprecated since 11
19761847f8eSopenharmony_ci   */
19861847f8eSopenharmony_ci  iv?: string;
19961847f8eSopenharmony_ci
20061847f8eSopenharmony_ci  /**
20161847f8eSopenharmony_ci   * Offset of the initial vector for AES-based encryption and decryption.
20261847f8eSopenharmony_ci   * The default value is 0.
20361847f8eSopenharmony_ci   *
20461847f8eSopenharmony_ci   * @type { ?string }
20561847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
20661847f8eSopenharmony_ci   * @since 3
20761847f8eSopenharmony_ci   * @deprecated since 11
20861847f8eSopenharmony_ci   */
20961847f8eSopenharmony_ci  ivOffset?: string;
21061847f8eSopenharmony_ci
21161847f8eSopenharmony_ci  /**
21261847f8eSopenharmony_ci   * Length of the initial vector for AES-based encryption and decryption.
21361847f8eSopenharmony_ci   * The default value is 16.
21461847f8eSopenharmony_ci   *
21561847f8eSopenharmony_ci   * @type { ?string }
21661847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
21761847f8eSopenharmony_ci   * @since 3
21861847f8eSopenharmony_ci   * @deprecated since 11
21961847f8eSopenharmony_ci   */
22061847f8eSopenharmony_ci  ivLen?: string;
22161847f8eSopenharmony_ci
22261847f8eSopenharmony_ci  /**
22361847f8eSopenharmony_ci   * Called when data is encrypted or decrypted successfully.
22461847f8eSopenharmony_ci   *
22561847f8eSopenharmony_ci   * @type { function }
22661847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
22761847f8eSopenharmony_ci   * @since 3
22861847f8eSopenharmony_ci   * @deprecated since 11
22961847f8eSopenharmony_ci   */
23061847f8eSopenharmony_ci  success: (data: CipherResponse) => void;
23161847f8eSopenharmony_ci
23261847f8eSopenharmony_ci  /**
23361847f8eSopenharmony_ci   * Called when data fails to be encrypted or decrypted.
23461847f8eSopenharmony_ci   *
23561847f8eSopenharmony_ci   * @type { function }
23661847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
23761847f8eSopenharmony_ci   * @since 3
23861847f8eSopenharmony_ci   * @deprecated since 11
23961847f8eSopenharmony_ci   */
24061847f8eSopenharmony_ci  fail: (data: string, code: number) => void;
24161847f8eSopenharmony_ci
24261847f8eSopenharmony_ci  /**
24361847f8eSopenharmony_ci   * Called when the execution is completed.
24461847f8eSopenharmony_ci   *
24561847f8eSopenharmony_ci   * @type { function }
24661847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
24761847f8eSopenharmony_ci   * @since 3
24861847f8eSopenharmony_ci   * @deprecated since 11
24961847f8eSopenharmony_ci   */
25061847f8eSopenharmony_ci  complete: () => void;
25161847f8eSopenharmony_ci}
25261847f8eSopenharmony_ci
25361847f8eSopenharmony_ci/**
25461847f8eSopenharmony_ci * Defines the cipher functions.
25561847f8eSopenharmony_ci *
25661847f8eSopenharmony_ci * @syscap SystemCapability.Security.Cipher
25761847f8eSopenharmony_ci * @since 3
25861847f8eSopenharmony_ci * @deprecated since 9
25961847f8eSopenharmony_ci * @useinstead ohos.security.cryptoFramework.Cipher
26061847f8eSopenharmony_ci */
26161847f8eSopenharmony_ciexport default class Cipher {
26261847f8eSopenharmony_ci  /**
26361847f8eSopenharmony_ci   * Encrypts or decrypts data using RSA.
26461847f8eSopenharmony_ci   *
26561847f8eSopenharmony_ci   * @param { CipherRsaOptions } options - RSA options
26661847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
26761847f8eSopenharmony_ci   * @since 3
26861847f8eSopenharmony_ci   * @deprecated since 9
26961847f8eSopenharmony_ci   * @useinstead ohos.security.cryptoFramework.Cipher
27061847f8eSopenharmony_ci   */
27161847f8eSopenharmony_ci  static rsa(options: CipherRsaOptions): void;
27261847f8eSopenharmony_ci
27361847f8eSopenharmony_ci  /**
27461847f8eSopenharmony_ci   * Encrypts or decrypts data using AES.
27561847f8eSopenharmony_ci   *
27661847f8eSopenharmony_ci   * @param { CipherAesOptions } options - AES options
27761847f8eSopenharmony_ci   * @syscap SystemCapability.Security.Cipher
27861847f8eSopenharmony_ci   * @since 3
27961847f8eSopenharmony_ci   * @deprecated since 9
28061847f8eSopenharmony_ci   * @useinstead ohos.security.cryptoFramework.Cipher
28161847f8eSopenharmony_ci   */
28261847f8eSopenharmony_ci  static aes(options: CipherAesOptions): void;
28361847f8eSopenharmony_ci}