Problem when trying to decryp encryped file with CryptoPP (C++)

  • C/C++
  • Thread starter CMV123
  • Start date
  • Tags
    File
In summary, someone encrypted a text file using AES128 with a binary key file, and after that used "base64Encode" over the encrypted file. However, when they try to decrypt the file, they always get an error saying that the DefaultDecryptor cannot decrypt the message with this passphrase.
  • #1
CMV123
1
0
Hi all,

I have a problem.

Someone I know encrypted a text file using AES128 by using binary key file, (He generate the binary key).
After that he uses "base64Encode" over the encryped file

I have the private binary key file.
Now, when I'm trying to decrypt the file, I do as follow:
1. Use "Base64Decoder" to get the encrypted file --> Pass successfully
2. Use the following:

Try using both functions:
FileSource f(in, true, new DefaultDecryptorWithMAC(passPhrase, new FileSink(out)));

FileSource f(in, true, new DefaultDecryptor(passPhrase, new FileSink(out)));

where:
in - is the input file (encrypted file)
passPharse - char* - location of the key file


but I always getting the following error:
terminate called after throwing an instance of 'CryptoPP::DefaultDecryptor::KeyBadErr'
what(): DefaultDecryptor: cannot decrypt message with this passphrase


Now when I'm trying to encrypt and decrypt by myself it works fine,
(I'm using the binary key he gave me)

1. FileSource f(in, true, new DefaultEncryptorWithMAC(passPhrase, new FileSink(out)));
2. FileSource(in, true, new Base64Encoder(new FileSink(out)));
3. FileSource(in, true, new Base64Decoder(new FileSink(out)));
4. FileSource f(in, true, new DefaultDecryptorWithMAC(passPhrase, new FileSink(out)));


Could anyone help me to understand what is my problem?
I'm guessing that the problem could be from 2 reasons:
1. Because this is a different algorithm form java AES128
2. There is a problem in the key, It can't read it right
 
Technology news on Phys.org
  • #2
I don't know anything about the implementation you are using so I don't know whether your code is correct, but from my experience such problems are usually the result of using different padding schemes.

Also, since it's AES, make sure you are using the same mode (ECB, CBC, CTR...) and initialization vector, if appropriate.

I'm pretty sure one of these two is the problem if your program correctly decrypts the stuff it encrypts.
 
Last edited:
  • #3



I would suggest checking the compatibility of the CryptoPP library with the Java AES128 algorithm. It is possible that the library is not able to decrypt the file correctly due to differences in implementation. It is also important to ensure that the key file is being read correctly and that there are no errors in the process of retrieving the key. Additionally, it may be helpful to consult with experts in the field of cryptography or seek assistance from the CryptoPP community to troubleshoot and resolve the issue.
 

1. What is CryptoPP and why is it used for encryption?

CryptoPP is a C++ library that provides a set of cryptographic algorithms for encryption, decryption, and other security-related functions. It is used to protect sensitive data by converting it into a code that is unreadable without the proper key.

2. How does encryption work in CryptoPP?

Encryption in CryptoPP uses various algorithms such as AES, RSA, and DES to convert plain text into a random and unreadable format. This process is reversible, meaning the encrypted data can be decrypted back to its original form using the same key used for encryption.

3. What could be causing the problem when trying to decrypt an encrypted file with CryptoPP?

The problem could be due to various reasons, such as using the wrong key for decryption, incorrect implementation of the encryption and decryption process, or a corrupted file.

4. How can I troubleshoot and fix the decryption problem with CryptoPP?

You can troubleshoot and fix the problem by double-checking the key used for decryption, verifying the implementation of the encryption and decryption process, and ensuring the file is not corrupted. You can also refer to the CryptoPP documentation or seek help from the community for further assistance.

5. Is CryptoPP a secure way to encrypt data?

Yes, CryptoPP is considered to be a secure way to encrypt data. It uses strong cryptographic algorithms and has been extensively tested and validated by experts. However, it is always recommended to follow best practices and use appropriate key management techniques to ensure maximum security.

Similar threads

  • Programming and Computer Science
Replies
2
Views
633
  • Programming and Computer Science
Replies
9
Views
862
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
3
Views
4K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
Replies
18
Views
1K
Back
Top