私はJCPABEプロジェクトを参照していますが、クラス内のメソッドを使用するとファイルやInputStreamを暗号化できますが、単純なJava文字列は暗号化できません。これらのメソッドを使用して文字列を暗号化/復号化するにはどうすればよいですか? 。どのように私は単純な文字列を暗号化/復号化することができ、私はバイト配列に文字列を変換しようとしているが、私はInputStream
でString
を変換する場合には(すなわちString.getBytes("UTF_8");
同じように動作しませんJCPABE Encypt Decrypt String
に例:? 私の簡単なコードを:
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型のメソッドencrypt(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