Я использовал реализацию OpenPGP Bouncy Castle в Java для шифрования текстового файла, и он работал нормально. Это код, который я использовал.
package org.jdamico.bc.openpgp.tests;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import java.security.SignatureException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openpgp.PGPException;
import org.jdamico.bc.openpgp.utils.PgpHelper;
import org.jdamico.bc.openpgp.utils.RSAKeyPairGenerator;
import org.junit.Test;
import java.io.File;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class TestBCOpenPGP {
private boolean isArmored = true;
private boolean integrityCheck = true;
private String pubKeyFile = "/root/Documents/T2.asc";
private String plainTextFile = "/root/Documents/otp.txt"; //create a text file to be encripted, before run the tests
private String cipherTextFile = "/root/Documents/cipher.txt";
public void encrypt() throws NoSuchProviderException, IOException, PGPException{
FileInputStream pubKeyIs = new FileInputStream(pubKeyFile);
FileOutputStream cipheredFileIs = new FileOutputStream(cipherTextFile);
PgpHelper.getInstance().encryptFile(cipheredFileIs, plainTextFile, PgpHelper.getInstance().readPublicKey(pubKeyIs), isArmored, integrityCheck);
cipheredFileIs.close();
pubKeyIs.close();
}
}
Но теперь мне нужно передать простой текст и открытый ключ в виде строк вместо файлов. Также мне нужно получить вывод в виде строки в операторе печати. Ваши предложения всегда приветствуются.