프로젝트에 JCPABE이 표시되지만 클래스에있는 메소드를 사용하여 파일이나 InputStream을 암호화 할 수 있지만 간단한 Java 문자열은 암호화 할 수 없습니다. 이 방법을 사용하여 문자열을 암호화/해독하는 방법은 무엇입니까? 나는 바이트 배열에서 문자열을 변환하는 시도했지만 내가 InputStream
에 String
을 변환 할 경우는 (I 암호화/어떻게 간단한 문자열을 해독JCPABE Encypt Decrypt String
예 예 String.getBytes("UTF_8");
동일하게 작동하지 않습니다.? 내 간단한 코드를 :
String test="Message";
policy="newyork or losangeles";
Cpabe.encrypt(publickey, policy, test, test);
나는이 메시지가 있습니다. Cpabe는 인수 (파일, 문자열, 문자열, 문자열) 적용 할 수 없습니다 유형의 방법은 암호화 (파일, 문자열, 파일, 파일)
기능 암호화는 다음과 같습니다.
public static void encrypt(File publicKeyFile, String policy, File inputFile, File outputFile) throws IOException, AbeEncryptionException {
AbePublicKey publicKey = AbePublicKey.readFromFile(publicKeyFile);
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(inputFile));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile))) {
encrypt(publicKey, policy, in, out);
}
내가의 기능을 변경 :
public static void encrypt(File publicKeyFile, String policy, String inputstr, String outputstr) throws IOException, AbeEncryptionException {
AbePublicKey publicKey = AbePublicKey.readFromFile(publicKeyFile);
try (String in = new String(inputstr);
String out = new String(outputstr)) {
encrypt(publicKey, policy, in, out);
}
}
하지만 난 다른 메시지가 : 자원 유형 문자열의 문자열에 java.lang.AutoCloseable를 구현하지 않고 문자열 밖으로; 암호화 중에는 다음 메시지가 표시됩니다. Cpabe 유형의 메소드 암호화 (AbePublicKey, String, InputStream, OutputStream)는 인수 (AbePublicKey, String, String, String)에 적용 할 수 없습니다.
이
는 2의 InputStream 매개 변수 기능입니다 :public static void encrypt(AbePublicKey publicKey, String policy, InputStream input, OutputStream output) throws AbeEncryptionException, IOException {
AbeEncrypted encrypted = encrypt(publicKey, policy, input);
encrypted.writeEncryptedData(output, publicKey);
}
이는 writeEncryptedData 방법입니다 : 할 수 없습니다 때문에 여러 가지 이유의
public void writeEncryptedData(OutputStream out, AbePublicKey publicKey) throws IOException {
AbeOutputStream abeOut = new AbeOutputStream(out, publicKey);
Version.writeToStream(abeOut);
cipher.writeToStream(abeOut);
abeOut.writeInt(iv.length);
abeOut.write(iv);
byte[] buffer = new byte[1024];
int len;
while ((len = dataStream.read(buffer)) != -1) {
abeOut.write(buffer, 0, len);
}
}
"작동하지 않습니다"는 좋은 오류 설명이 아닙니다. 코드 및 정확한 실패 (예 : 스택 추적 및 발생한 행 표시)를 알려주십시오. 우리는 당신을 위해 당신의 솔루션을 쓰려고 여기 온 것이 아닙니다. –
@MaartenBodewes 전 너무 좋아요. 당신의 힌트를 가져 주셔서 감사합니다. 내 질문에 대한 설명을 업데이트했습니다. 나는 해결책을 원하지 않는다. 나는 골동품이며 실수를 이해하고 싶습니다. – CipherX