这里有一个通过输入文件进行加密解密再输出文件保存的例子,我想把它改成从JTextArea里读取字符串加密后再输出到JTextArea怎么改
import java.io.*;
import java.security.*;
import javax.crypto.*;
/**
使用方法:
java RSATest -genkey public private
java RSATest -encrypt plaintext encrypted public
java RSATest -decrypt encrypted decrypted private
*/
public class RSATest
{
public static void main(String[] args)
{
try
{
if (args[0].equals( "-genkey "))//产生密钥对
{
KeyPairGenerator pairgen = KeyPairGenerator.getInstance( "RSA ");
SecureRandom random = new SecureRandom();
pairgen.initialize(KEYSIZE, random);
KeyPair keyPair = pairgen.generateKeyPair();
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(args[1]));
out.writeObject(keyPair.getPublic());
out.close();
out = new ObjectOutputStream(new FileOutputStream(args[2]));
out.writeObject(keyPair.getPrivate());
out.close();
}
else if (args[0].equals( "-encrypt "))//加密
{
KeyGenerator keygen = KeyGenerator.getInstance( "AES ");
SecureRandom random = new SecureRandom();
keygen.init(random);
SecretKey key = keygen.generateKey();
// wrap with RSA public key
ObjectInputStream keyIn = new ObjectInputStream(new FileInputStream(args[3]));