1/* 2 * Copyright (c) 2020-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit CryptoArchitectureKit 19 */ 20 21/** 22 * Defines the cipher response. 23 * 24 * @typedef CipherResponse 25 * @syscap SystemCapability.Security.Cipher 26 * @since 3 27 * @deprecated since 11 28 */ 29export interface CipherResponse { 30 /** 31 * response text 32 * 33 * @type { string } 34 * @syscap SystemCapability.Security.Cipher 35 * @since 3 36 * @deprecated since 11 37 */ 38 text: string; 39} 40 41/** 42 * Defines the rsa cipher options. 43 * 44 * @typedef CipherRsaOptions 45 * @syscap SystemCapability.Security.Cipher 46 * @since 3 47 * @deprecated since 11 48 */ 49export interface CipherRsaOptions { 50 /** 51 * Action type. 52 * The options are as follows: 53 * encrypt: Encrypts data. 54 * decrypt: Decrypts data. 55 * 56 * @type { string } 57 * @syscap SystemCapability.Security.Cipher 58 * @since 3 59 * @deprecated since 11 60 */ 61 action: string; 62 63 /** 64 * Text content to be encrypted or decrypted. 65 * The text to be encrypted must be a common text and cannot exceed the length calculated based on the formula (keySize/8 - 66). 66 * keySize indicates the key length. 67 * For example, if the key length is 1024 bytes, the text cannot exceed 62 bytes (1024/8 - 66 = 62). 68 * The text content to be decrypted must be a binary value encoded using Base64. 69 * The default format is used for Base64 encoding. 70 * 71 * @type { string } 72 * @syscap SystemCapability.Security.Cipher 73 * @since 3 74 * @deprecated since 11 75 */ 76 text: string; 77 78 /** 79 * Keys encrypted using RSA. 80 * During encryption, this parameter is a public key. 81 * During decryption, it is a private key. 82 * 83 * @type { string } 84 * @syscap SystemCapability.Security.Cipher 85 * @since 3 86 * @deprecated since 11 87 */ 88 key: string; 89 90 /** 91 * RSA algorithm padding. 92 * The default value is RSA/None/OAEPWithSHA256AndMGF1Padding. 93 * 94 * @type { ?string } 95 * @syscap SystemCapability.Security.Cipher 96 * @since 3 97 * @deprecated since 11 98 */ 99 transformation?: string; 100 101 /** 102 * Called when data is encrypted or decrypted successfully. 103 * 104 * @type { function } 105 * @syscap SystemCapability.Security.Cipher 106 * @since 3 107 * @deprecated since 11 108 */ 109 success: (data: CipherResponse) => void; 110 111 /** 112 * Called when data fails to be encrypted or decrypted. 113 * 114 * @type { function } 115 * @syscap SystemCapability.Security.Cipher 116 * @since 3 117 * @deprecated since 11 118 */ 119 fail: (data: string, code: number) => void; 120 121 /** 122 * Called when the execution is completed. 123 * 124 * @type { function } 125 * @syscap SystemCapability.Security.Cipher 126 * @since 3 127 * @deprecated since 11 128 */ 129 complete: () => void; 130} 131 132/** 133 * Defines the aes cipher options. 134 * 135 * @typedef CipherAesOptions 136 * @syscap SystemCapability.Security.Cipher 137 * @since 3 138 * @deprecated since 11 139 */ 140export interface CipherAesOptions { 141 /** 142 * Action type. 143 * The options are as follows: 144 * encrypt: Encrypts data. 145 * decrypt: Decrypts data. 146 * 147 * @type { string } 148 * @syscap SystemCapability.Security.Cipher 149 * @since 3 150 * @deprecated since 11 151 */ 152 action: string; 153 154 /** 155 * Text content to be encrypted or decrypted. 156 * The text to be encrypted must be a common text. 157 * The text content to be decrypted must be a binary value encoded using Base64. 158 * The default format is used for Base64 encoding. 159 * 160 * @type { string } 161 * @syscap SystemCapability.Security.Cipher 162 * @since 3 163 * @deprecated since 11 164 */ 165 text: string; 166 167 /** 168 * Key used for encryption or decryption, which is a character string encrypted using Base64. 169 * 170 * @type { string } 171 * @syscap SystemCapability.Security.Cipher 172 * @since 3 173 * @deprecated since 11 174 */ 175 key: string; 176 177 /** 178 * Encryption mode and padding of the AES algorithm. 179 * The default value is AES/CBC/PKCS5Padding. 180 * 181 * @type { ?string } 182 * @syscap SystemCapability.Security.Cipher 183 * @since 3 184 * @deprecated since 11 185 */ 186 transformation?: string; 187 188 /** 189 * Initial vector for AES-based encryption and decryption. 190 * The value is a character string encoded using Base64. 191 * The default value is the key value. 192 * 193 * @type { ?string } 194 * @syscap SystemCapability.Security.Cipher 195 * @since 3 196 * @deprecated since 11 197 */ 198 iv?: string; 199 200 /** 201 * Offset of the initial vector for AES-based encryption and decryption. 202 * The default value is 0. 203 * 204 * @type { ?string } 205 * @syscap SystemCapability.Security.Cipher 206 * @since 3 207 * @deprecated since 11 208 */ 209 ivOffset?: string; 210 211 /** 212 * Length of the initial vector for AES-based encryption and decryption. 213 * The default value is 16. 214 * 215 * @type { ?string } 216 * @syscap SystemCapability.Security.Cipher 217 * @since 3 218 * @deprecated since 11 219 */ 220 ivLen?: string; 221 222 /** 223 * Called when data is encrypted or decrypted successfully. 224 * 225 * @type { function } 226 * @syscap SystemCapability.Security.Cipher 227 * @since 3 228 * @deprecated since 11 229 */ 230 success: (data: CipherResponse) => void; 231 232 /** 233 * Called when data fails to be encrypted or decrypted. 234 * 235 * @type { function } 236 * @syscap SystemCapability.Security.Cipher 237 * @since 3 238 * @deprecated since 11 239 */ 240 fail: (data: string, code: number) => void; 241 242 /** 243 * Called when the execution is completed. 244 * 245 * @type { function } 246 * @syscap SystemCapability.Security.Cipher 247 * @since 3 248 * @deprecated since 11 249 */ 250 complete: () => void; 251} 252 253/** 254 * Defines the cipher functions. 255 * 256 * @syscap SystemCapability.Security.Cipher 257 * @since 3 258 * @deprecated since 9 259 * @useinstead ohos.security.cryptoFramework.Cipher 260 */ 261export default class Cipher { 262 /** 263 * Encrypts or decrypts data using RSA. 264 * 265 * @param { CipherRsaOptions } options - RSA options 266 * @syscap SystemCapability.Security.Cipher 267 * @since 3 268 * @deprecated since 9 269 * @useinstead ohos.security.cryptoFramework.Cipher 270 */ 271 static rsa(options: CipherRsaOptions): void; 272 273 /** 274 * Encrypts or decrypts data using AES. 275 * 276 * @param { CipherAesOptions } options - AES options 277 * @syscap SystemCapability.Security.Cipher 278 * @since 3 279 * @deprecated since 9 280 * @useinstead ohos.security.cryptoFramework.Cipher 281 */ 282 static aes(options: CipherAesOptions): void; 283}