You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encrypted a file using a .Net 8.0 F# program that references BouncyCastle.Cryptography version 2.4.0. When I try to decrypt it using Kleopatra, I get these messages:
gpg: encrypted with rsa4096 key, ID 201748...., created 2019-04-15
"..."
gpg: used key is not marked for encryption use.
gpg: WARNING: cipher algorithm CAST5 not found in recipient preferences
gpg: zlib inflate problem: invalid block type
Here are the version numbers:
Kleopatra: 3.2.2.2311170 (Gpg4win-4.3.1)
GnuPG 2.4.5
Libgcrypt 1.10.3
Here is the source code of the F# program:
openSystemopenSystem.IOopenSystem.TextopenOrg.BouncyCastle.BcpgopenOrg.BouncyCastle.Bcpg.OpenPgpopenOrg.BouncyCastle.SecurityletreadPublicKeyFromStream(input:Stream):PgpPublicKey =letstream2= PgpUtilities.GetDecoderStream(input)letpgpPub= PgpPublicKeyRingBundle(stream2)letkey= pgpPub.GetKeyRings()|> Seq.collect (fun kr -> kr.GetPublicKeys())|> Seq.tryFind (fun k -> k.IsEncryptionKey)if key.IsSome then
key.Value
else
failwith "Unable to find a public key in the stream"letreadPublicKeyFromString(publicKey:string)=use stream =new MemoryStream(Encoding.UTF8.GetBytes(publicKey))
readPublicKeyFromStream stream
letreadPublicKeyFromFile(fileName:string)=letpublicKey= File.ReadAllText(fileName, Encoding.UTF8)
readPublicKeyFromString publicKey
letcompressFile(algorithm:CompressionAlgorithmTag)(inputFileName:string):string =letoutputFileName= Path.GetTempFileName()//use fsout = File.Create(outputFileName)use fsout =new MemoryStream()letinputFileInfo= FileInfo(inputFileName)// use fsinput = File.OpenRead(inputFileName)letinputContent= File.ReadAllBytes(inputFileName)letcomData= PgpCompressedDataGenerator(algorithm)use pOut = PgpLiteralDataGenerator().Open(comData.Open(fsout), PgpLiteralData.Binary, inputFileName, inputContent.Length, DateTime.Now)//fsinput.CopyTo(pOut)
pOut.Write(inputContent,0, inputContent.Length)
pOut.Flush()
pOut.Close()
fsout.Flush()
File.WriteAllBytes(outputFileName, fsout.ToArray())
outputFileName
letencryptFile(inputFileName:string)(outputFileName:string)(encKeyFileName:string)(withIntegrityCheck:bool)=letencKey= readPublicKeyFromFile encKeyFileName
use fsout = File.Create(outputFileName)use outputStream =new ArmoredOutputStream(fsout)letcompressedFileName= compressFile CompressionAlgorithmTag.Zip inputFileName
letencGen=new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.Cast5, withIntegrityCheck,new SecureRandom())
encGen.AddMethod(encKey)letcontent= File.ReadAllBytes(compressedFileName)letcompressedFileNameInfo= FileInfo(compressedFileName)letcOut= encGen.Open(outputStream, content.Length )//use compressedFileStream = File.OpenRead(compressedFileName)//compressedFileStream.CopyTo(cOut)
cOut.Write(content,0, content.Length)
cOut.Close()
outputFileName
I should also mention the file is decrypted successfully using another BC custom program which is great!
Any ideas? I tried to decrypt the file using the gnugpg command line but it returns the same message as above.
I know this is a question about another tool, but if you have any insight it would be great if you can share it. While it is not a requirement that the file should be decrypted using Kleopatra, it is useful to be able to do so for testing purposes.
Edit2: Using CompressionAlgorithmTag.BZip2 instead of CompressionAlgorithmTag.Zip seems to work, i.e. the file is decrypted successfully by Kleopatra.
Edit3 - 2024-Oct-15: Today I tested again the decryption via Kleopatra, and actually it looks like Kleopatra cannot decrypt encrypted files that were compressed with BZip2 and Zip, but it can decrypt files that were compressed with ZLib. I am not too sure what happened in my previous tests, I might have made a mistake previously.
Anyway, if you have any suggestions or insight it would be great if you can share it. 🙏
The text was updated successfully, but these errors were encountered:
Hello,
I encrypted a file using a .Net 8.0 F# program that references BouncyCastle.Cryptography version 2.4.0. When I try to decrypt it using Kleopatra, I get these messages:
Here are the version numbers:
Kleopatra: 3.2.2.2311170 (Gpg4win-4.3.1)
GnuPG 2.4.5
Libgcrypt 1.10.3
Here is the source code of the F# program:
I should also mention the file is decrypted successfully using another BC custom program which is great!
Any ideas? I tried to decrypt the file using the gnugpg command line but it returns the same message as above.
I know this is a question about another tool, but if you have any insight it would be great if you can share it. While it is not a requirement that the file should be decrypted using Kleopatra, it is useful to be able to do so for testing purposes.
Thank you
Edit: I also found this thread: https://forum.gnupg.org/t/zlib-inflate-problem-invalid-block-typ/3551
Edit2: Using
CompressionAlgorithmTag.BZip2
instead ofCompressionAlgorithmTag.Zip
seems to work, i.e. the file is decrypted successfully by Kleopatra.Edit3 - 2024-Oct-15: Today I tested again the decryption via Kleopatra, and actually it looks like Kleopatra cannot decrypt encrypted files that were compressed with BZip2 and Zip, but it can decrypt files that were compressed with ZLib. I am not too sure what happened in my previous tests, I might have made a mistake previously.
Anyway, if you have any suggestions or insight it would be great if you can share it. 🙏
The text was updated successfully, but these errors were encountered: