📄 original.txt
字号:
Use the keytool utility (part of the JAVA development kit) to generate a so‐called keystore that contains a key pair for the RSA algorithm (key length 512 bits). This will enable your application to read the keys from the keystore every time they are needed.
Write a JAVA program that reads the private key and the certificate for the public key from the keystore (hints: use the KeyStore class to access your keystore; the Certificate object also contains the public key).
Implement an application that encrypts a file of arbitrary size and another application that decrypts the encrypted file. Use the public key from the keystore for encryption and the private key for decryption. However, remember that using asymmetric cryptography (RSA) directly for encrypting larger files is inefficient! Therefore, use a combination of asymmetric and symmetric cryptography for encrypting and decrypting the file:
First, create a symmetric AES key with 128 bits key length for encrypting the file, encrypt this AES key using the public RSA key from the keystore (hint: have a look at the wrap/unwrap methods of the Cipher class), and store the encrypted AES key with the encrypted file. That is, the encrypted file contains the RSA‐encrypted AES key and the AES‐encrypted data from the source file.
The decrypting application shall read the encrypted AES key from the encrypted file, decode the AES key using the private RSA key from the keystore, and then decrypt the rest of the file using this AES key.
Compare the original file and the decrypted file to make sure that they are identical.
Why does it make sense to use the public key for encryption of the symmetric key and the private key for decryption of the symmetric key to achieve secrecy instead of the other way around?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -