145 Star 1.4K Fork 1.7K

OpenHarmony/applications_app_samples

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README

Crypto Framework

Introduction

This sample shows how @ohos.security.cryptoFramework works to implement the function of encrypting, decrypting, signing and verifying text file. The implementation scenario is as follows:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Usage

  1. 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. Its contents are displayed in the File Content text box, 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. 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 The encrypted message content is displayed in the Encrypted Content text box below.

  2. 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. Its contents are displayed in the File Content text box, Click Select Key to select the same key file as Encryption. 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. The decrypted message content is displayed in the Decrypted Content text box below.

  3. 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. Its contents are displayed in the File Content text box, 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. 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.

  4. 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. Its contents are displayed in the File Content text box, 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, After selecting the text file, key file, and signature file, click the Verify button to complete the signature verification.

Dependency

Constraints

  1. This sample can only be run on standard-system devices.
  2. This sample has been adapted to the API version 9 SDK, version number 3.2.12.2.
  3. This sample requires DevEco Studio 3.1 Release(Build Version: 3.1.0.500) to compile and run.
  4. 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.
  5. 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.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony/applications_app_samples.git
git@gitee.com:openharmony/applications_app_samples.git
openharmony
applications_app_samples
applications_app_samples
master

Search