使用 Java (Groovy) 解密 GPG 文件
我在网上和 stackoverflow 上尝试了很多不同的例子,但没有成功。 没有密码,只有 .gpg 或 .asc pub/sec 文件。
根据离开公司的前项目维护人员提供的 .gpg 文件,我正在使用 Kleopatra 导出 .asc 文件。
我遇到与 BouncyCastle Open PGP - 中的未知对象相同的错误流 47
File decryptFile(File file){
String newFileName = "/tmp/encrypted-" + file.getName().replace(".gpg", "")
File newFile = new File(newFileName)
File tempFile = getFileFromResource('seckeyascii.asc')
// Just to see that files are read properly, it's fine
logger.log(tempFile.getText())
// Attempt 1
new Decryptor(
// new Key(getFileFromResource(RESOURCE_PUBRING)),
// new Key(getFileFromResource(RESOURCE_SECRING))
new Key(getFileFromResource('pubkeyascii.asc')),
new Key(getFileFromResource('seckeyascii.asc'))
).decrypt(file, newFile)
// Attempt 2
File pubringFile = getFileFromResource(RESOURCE_PUBRING)
File secringFile = getFileFromResource(RESOURCE_SECRING)
KeyringConfig keyringConfig = KeyringConfigs.withKeyRingsFromFiles(pubringFile, secringFile, KeyringConfigCallbacks.withUnprotectedKeys())
try {
FileInputStream cipherTextStream = new FileInputStream(file.getPath())
FileOutputStream fileOutput = new FileOutputStream(newFileName)
BufferedOutputStream bufferedOut = new BufferedOutputStream(fileOutput)
InputStream plaintextStream = BouncyGPG
.decryptAndVerifyStream()
.withConfig(keyringConfig)
.andIgnoreSignatures()
.fromEncryptedInputStream(cipherTextStream)
}
catch (Exception e){
logger.log("Error decrypting file: ${e.getMessage()}")
return null
}
finally {
Streams.pipeAll(plaintextStream, bufferedOut)
}
return newFile
}
我在所有尝试中得到的是: 迭代器无法获取下一个对象:流中的未知对象:47
我尝试将密钥文件转换为 ANSI 或 ASCII 西欧/OEM850,但没有帮助。
这是使用不同的 bouncycastle 库,例如 name.neuhalfen.projects.crypto.bouncycastle.openpgp 或 org.c02e.jpgpj
I've tried many different examples online and from stackoverflow, but to no avail.
There is no passphrase, just either .gpg or .asc pub/sec files.
I'm using Kleopatra to export the .asc files, according to the provided .gpg files from the previous project maintainer who left the company.
I'm getting the same error as in BouncyCastle Open PGP - unknown object in stream 47
File decryptFile(File file){
String newFileName = "/tmp/encrypted-" + file.getName().replace(".gpg", "")
File newFile = new File(newFileName)
File tempFile = getFileFromResource('seckeyascii.asc')
// Just to see that files are read properly, it's fine
logger.log(tempFile.getText())
// Attempt 1
new Decryptor(
// new Key(getFileFromResource(RESOURCE_PUBRING)),
// new Key(getFileFromResource(RESOURCE_SECRING))
new Key(getFileFromResource('pubkeyascii.asc')),
new Key(getFileFromResource('seckeyascii.asc'))
).decrypt(file, newFile)
// Attempt 2
File pubringFile = getFileFromResource(RESOURCE_PUBRING)
File secringFile = getFileFromResource(RESOURCE_SECRING)
KeyringConfig keyringConfig = KeyringConfigs.withKeyRingsFromFiles(pubringFile, secringFile, KeyringConfigCallbacks.withUnprotectedKeys())
try {
FileInputStream cipherTextStream = new FileInputStream(file.getPath())
FileOutputStream fileOutput = new FileOutputStream(newFileName)
BufferedOutputStream bufferedOut = new BufferedOutputStream(fileOutput)
InputStream plaintextStream = BouncyGPG
.decryptAndVerifyStream()
.withConfig(keyringConfig)
.andIgnoreSignatures()
.fromEncryptedInputStream(cipherTextStream)
}
catch (Exception e){
logger.log("Error decrypting file: ${e.getMessage()}")
return null
}
finally {
Streams.pipeAll(plaintextStream, bufferedOut)
}
return newFile
}
What I'm getting in all tries is:
Iterator failed to get next object: unknown object in stream: 47
I tried converting the key files into ANSI or ASCII Western Europe/OEM850, didn't help.
This is using different bouncycastle libs like name.neuhalfen.projects.crypto.bouncycastle.openpgp or org.c02e.jpgpj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论