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:
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.
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.
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.
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.
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.
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.
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.
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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。