私はhttps://github.com/TomRoush/PdfBox-Androidを使用して、hereのようなpdfを暗号化しますが、動作しません。pdfを暗号化することはPdfBox-Androidでは機能しません
FoxitとAdobeReaderで結果を確認します。 AdobeReaderは私のファイルが壊れていると言いますが、Foxitは私にパスワードダイアログを表示します。しかし、私はFoxitも私のファイルを復号化できないようにしたいと思うことができます。
私は上記のkeyLength = 256を設定しますが、私は他の2つのkeyLength値を試しましたが、ファイルが暗号化されていません。
私は何かを見逃しましたか、暗号化されていませんでしたか?
ここTom hereからの私の質問への答えの後に私のコード
static {
Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
}
public void createPdf() {
File root = android.os.Environment.getExternalStorageDirectory();
String path = root.getAbsolutePath() + "/Download/crypt.pdf";
int keyLength = 256;
AccessPermission ap = new AccessPermission();
StandardProtectionPolicy spp = new StandardProtectionPolicy("12345", "", ap);
spp.setEncryptionKeyLength(keyLength);
spp.setPermissions(ap);
BouncyCastleProvider provider = new BouncyCastleProvider();
Security.addProvider(provider);
PDFont font = PDType1Font.HELVETICA;
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
try {
PDPageContentStream contentStream = new PDPageContentStream(document, page);
// Write Hello World in blue text
contentStream.beginText();
contentStream.setNonStrokingColor(15, 38, 192);
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(100, 700);
contentStream.showText("Hello World");
contentStream.endText();
contentStream.close();
// Save the final pdf document to a file
document.protect(spp);
document.save(path);
document.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Androidのポートは、2.0.xではなく1.8.xバージョンに基づいています。したがって、キーの長さ40と128だけがサポートされていることを示す[1.8.x暗号化クックブックエントリー](https://pdfbox.apache.org/1.8/cookbook/encryption.html)を見てください。したがって、あなたが256のために得るものは、使用すべきではありません。さらに、AndroidのポートはBouncyCastleではなくSpongyCastleを使用しているので、そのセキュリティプロバイダを使用してみてください。 – mkl
ありがとうございました...しかし私が言ったように:私は40と128も試しましたが、うまくいきません。また、私は[static { Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider()、1);を使用しているので、SpongyCastle ...(私は思った:-); }]アクティビティの先頭に... – HowardS
これらは別々のプロジェクトであることに注意してください。アンドロイドのソースコードリポジトリには、暗号化のための単体テストがありません/復号化:-( –