1e41f4b71Sopenharmony_ci# Converting SM2 Ciphertext 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThe Crypto framework supports the SM2 ciphertext in ASN.1 format. The SM2 ciphertext consists of C1, C3 (the hash value), and C2 (the encrypted data). For details about the specifications, see [SM2 Ciphertext Format](crypto-asym-encrypt-decrypt-spec.md#sm2-ciphertext-format). 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciYou can convert the SM2 ciphertext into ASN.1 format based on the SM2 parameters specified or obtain SM2 parameters from the SM2 ciphertext in ASN.1 format. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci**Generating SM2 Ciphertext in ASN.1 Format** 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci1. Create an [SM2CipherTextSpec](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#sm2ciphertextspec12) instance to specify SM2 ciphertext parameters. If the ciphertext is not in ASN.1 format, you need to obtain the required parameters. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci2. Use [genCipherTextBySpec](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#genciphertextbyspec12) with the **SM2CipherTextSpec** instance to generate the SM2 ciphertext in ASN.1 format. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci3. Decrypt the SM2 ciphertext using the **cryptoFramework** APIs. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci```ts 19e41f4b71Sopenharmony_ciimport { cryptoFramework } from '@kit.CryptoArchitectureKit'; 20e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_cifunction testGenCipherTextBySpec() { 23e41f4b71Sopenharmony_ci let spec : cryptoFramework.SM2CipherTextSpec = { 24e41f4b71Sopenharmony_ci xCoordinate: BigInt('20625015362595980457695435345498579729138244358573902431560627260141789922999'), 25e41f4b71Sopenharmony_ci yCoordinate: BigInt('48563164792857017065725892921053777369510340820930241057309844352421738767712'), 26e41f4b71Sopenharmony_ci cipherTextData: new Uint8Array([100, 227, 78, 195, 249, 179, 43, 70, 242, 69, 169, 10, 65, 123]), 27e41f4b71Sopenharmony_ci hashData: new Uint8Array([87, 167, 167, 247, 88, 146, 203, 234, 83, 126, 117, 129, 52, 142, 82, 54, 152, 226, 201, 111, 143, 115, 169, 125, 128, 42, 157, 31, 114, 198, 109, 244]), 28e41f4b71Sopenharmony_ci } 29e41f4b71Sopenharmony_ci // The data can be decrypted using cryptoFramework APIs. 30e41f4b71Sopenharmony_ci let data = cryptoFramework.SM2CryptoUtil.genCipherTextBySpec(spec, 'C1C3C2'); 31e41f4b71Sopenharmony_ci console.info('genCipherTextBySpec success'); 32e41f4b71Sopenharmony_ci} 33e41f4b71Sopenharmony_ci``` 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**Obtaining SM2 Parameters from Ciphertext in ASN.1 Format** 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci1. Check that the SM2 ciphertext is in ASN.1 format. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci2. Use [getCipherTextSpec](../../reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md#genciphertextbyspec12) to obtain SM2 parameters from the ciphertext. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci3. You can combine SM2 parameters based on service requirements to generate SM2 ciphertext in other formats. 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci```ts 46e41f4b71Sopenharmony_ciimport { cryptoFramework } from '@kit.CryptoArchitectureKit'; 47e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_cifunction testGetCipherTextSpec() { 50e41f4b71Sopenharmony_ci let cipherTextArray = new Uint8Array([48, 118, 2, 32, 45, 153, 88, 82, 104, 221, 226, 43, 174, 21, 122, 248, 5, 232, 105, 41, 92, 95, 102, 224, 216, 149, 85, 236, 110, 6, 64, 188, 149, 70, 70, 183, 2, 32, 107, 93, 198, 247, 119, 18, 40, 110, 90, 156, 193, 158, 205, 113, 170, 128, 146, 109, 75, 17, 181, 109, 110, 91, 149, 5, 110, 233, 209, 78, 229, 96, 4, 32, 87, 167, 167, 247, 88, 146, 203, 234, 83, 126, 117, 129, 52, 142, 82, 54, 152, 226, 201, 111, 143, 115, 169, 125, 128, 42, 157, 31, 114, 198, 109, 244, 4, 14, 100, 227, 78, 195, 249, 179, 43, 70, 242, 69, 169, 10, 65, 123]); 51e41f4b71Sopenharmony_ci let cipherText : cryptoFramework.DataBlob = {data : cipherTextArray}; 52e41f4b71Sopenharmony_ci let spec : cryptoFramework.SM2CipherTextSpec = cryptoFramework.SM2CryptoUtil.getCipherTextSpec(cipherText, 'C1C3C2'); 53e41f4b71Sopenharmony_ci console.info('getCipherTextSpec success'); 54e41f4b71Sopenharmony_ci} 55e41f4b71Sopenharmony_ci``` 56