1# Crypto Framework 2 3### Introduction 4 5This sample shows how [@ohos.security.cryptoFramework](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md) works to implement the function of encrypting, decrypting, signing and verifying text file. The implementation scenario is as follows: 6 71. The software needs to encrypt and store the local text file, and it needs to call Crypto Framework to select the key text file and encrypt the local text file, among which the key text file can be generated by Crypto Framework. 8 92. The software needs to decrypt and store the local text file, and needs to call Crypto Framework to select the key text file and decrypt the local text file, where the key text file can be generated by Crypto Framework. 10 113. The software needs to sign the stored local text file, call the encryption and Crypto Framework to select the key text file, and sign the integrity of the local text file, among which the key text file can be generated by Crypto Framework. 12 134. The software needs to verify the signature integrity of the stored local text file, and needs to call Crypto Framework to select the key text file and the signature file, and verify and sign the file, among which the key text file can be generated by Crypto Framework. 14 15### Usage 16 171. Click **Encrypted** in the tab bar of the main page, click **Open File** in the encrypt interface, select the text file through the file chooser, and automatically return to the encrypt interface after selection. 18 Its contents are displayed in the **File Content** text box, 19 Click **Select Key** to select the key file, if there is no key file, you can generate and save the key file through the file chooser by clicking **Generate AES Key Randomly** on the encryption interface. 20 After selecting the text file and key file, click the **Encrypt** button to complete the encryption and save the ciphertext file through the file chooser.s 21 The encrypted message content is displayed in the **Encrypted Content** text box below. 22 232. Click **Decrypt** in the tab bar of the main page, click **Open File** on the decrypt interface, select the text file through the file chooser, and automatically return to the decrypt interface after selection. 24 Its contents are displayed in the **File Content** text box, 25 Click **Select Key** to select the same key file as Encryption. 26 After selecting the text file and key file, click the **Decrypt** button to complete the decryption and save the plaintext file through the file chooser. 27 The decrypted message content is displayed in the **Decrypted Content** text box below. 28 293. Click **Signature** in the tab bar of the main page, click **Open File** on the sign interface, select the text file through the file chooser, and automatically return to the sign interface after selection. 30 Its contents are displayed in the **File Content** text box, 31 Click **Select Key** to select the key file, if there is no key file, you can generate and save the key file through the file selector by clicking **Generate RSA Key Randomly** on the signature interface, note that RSA key generation takes a long time. 32 After selecting the text file and key file, click the **Sign** button to complete the integrity signature and save the signature file through the file chooser. 33 344. Click the **Verify** tab bar of the main page, click **Open File** on the verify interface, select the text file through the file chooser, and automatically return to the verify interface after selection. 35 Its contents are displayed in the **File Content** text box, 36 Click **Select Key** to select a key file that matches the signature. Click **Select Signature File** to select the signature file saved when signing through the file chooser, 37 After selecting the text file, key file, and signature file, click the **Verify** button to complete the signature verification. 38 39### Dependency 40 41* filePicker[@ohos.file.picker](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) 42* fileManager[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) 43* UI Ability Context[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md) 44 45### Constraints 46 471. This sample can only be run on standard-system devices. 482. This sample has been adapted to the API version 9 SDK, version number 3.2.12.2. 493. This sample requires DevEco Studio 3.1 Release(Build Version: 3.1.0.500) to compile and run. 504. This sample uses filePicker to select file, the files saved with filePicker, such as new keys generated, can be updated in real time, but the files directly pushed to the folder, they requires reboot the device and refresh the display. 515. This sample supports text file currently only English characters, and as a demonstration, the length of text that can be used successfully does not exceed 8,000 bytes. 52 53