Hello again, Stephen.

If you encrypt then base-64 encode, you must base-64 decode then decrypt. You
are attempting to decrypt base-64 encoded ciphertext, not the ciphertext
itself.

>From test.cpp:
string DecryptString(const char *instr, const char *passPhrase)
{
    string outstr;

    HexDecoder decryptor(new DefaultDecryptorWithMAC(passPhrase, new
StringSink(outstr)));
    decryptor.Put((byte *)instr, strlen(instr));
    decryptor.MessageEnd();

    return outstr;
}

Which means your cfbDecrypter should look more like:
StreamTransformationFilter *cfbDecryptor =
new StreamTransformationFilter (aes_decrypt,
new StringSink (plaintext));


and your StringSource should look more like:
StringSource source (new Base64Decoder(ciphertext), true, cfbDecryptor);

NOTE that I haven't tested this, you may have to make some "adjustments" to
it.
I don't use them quite like that.

Rickey

----- Original Message -----
From: "Stephen torri" <[EMAIL PROTECTED]>
To: "Rickey Braddam" <[EMAIL PROTECTED]>
Cc: "cryptopp" <[EMAIL PROTECTED]>
Sent: Saturday, November 15, 2003 1:46 PM
Subject: Decryption in CFB_Mode<AES>


> Here is the code that I am using to encrypt and decrypt a text. What I
> do not see is how the decryption is failing to work. Below is the output
> (char and hex for both the plain text). Question is why is the decrypt
> code rubbish and not the original plain text?
>
> -----------------------
>     encrypt code
> -----------------------
> string plaintext = ... input text ...
> string ciphertext;
>
> CFB_Mode<AES>::Encryption aes_encrypt (m_encryKey,
> AES::DEFAULT_KEYLENGTH, m_iv);
>
> StreamTransformationFilter *cfbEncryptor =
> new StreamTransformationFilter (aes_encrypt,
> new Base64Encoder (new StringSink (ciphertext)));
>
> StringSource source (plaintext, true, cfbEncryptor);
>
> -------------------------
>     encrypt output
> -------------------------
>
> Plaintext char:  J  i  m     C  a  r  r  e  y
>   B  r  u  c  e     A  l  m  i  g  h  t  y
>
> Plaintext hex:  0x4a  0x69  0x6d  0x20  0x43  0x61  0x72  0x72  0x65
> 0x79  0xa  0x42  0x72  0x75  0x63  0x65  0x20  0x41  0x6c  0x6d  0x69
> 0x67  0x68  0x74  0x79
>
> Ciphertext char:  3  i  P  n  2  M  U  6  D  j  E  c  /  P  9  d  /  5
> g  h  O  z  3  v  f  u  6  X  V  W  n  5  c  w
>
> Ciphertext hex:  0x33  0x69  0x50  0x6e  0x32  0x4d  0x55  0x36  0x44
> 0x6a  0x45  0x63  0x2f  0x50  0x39  0x64  0x2f  0x35  0x67  0x68  0x4f
> 0x7a  0x33  0x76  0x66  0x75  0x36  0x58  0x56  0x57  0x6e  0x35  0x63
> 0x77  0xa
>
> Open the file and decrypt contents: Loading
> /home/storri/Documents/StephenTorri/cs502_project/src/data.txt
>
> -----------------------
>    decrypt code
> -----------------------
> CFB_Mode<AES>::Decryption aes_decrypt (m_encryKey,
> AES::DEFAULT_KEYLENGTH, m_iv);
>
> StreamTransformationFilter *cfbDecryptor =
> new StreamTransformationFilter (aes_decrypt,
> new Base64Decoder (new StringSink (plaintext)));
>
> StringSource source (ciphertext, true, cfbDecryptor);
>
> -----------------------
>    decrypt output
> -----------------------
>
> Ciphertext char:  3  i  P  n  2  M  U  6  D  j  E  c  /  P  9  d  /  5
> g  h  O  z  3  v  f  u  6  X  V  W  n  5  c  w
>
> Ciphertext hex:  0x33  0x69  0x50  0x6e  0x32  0x4d  0x55  0x36  0x44
> 0x6a  0x45  0x63  0x2f  0x50  0x39  0x64  0x2f  0x35  0x67  0x68  0x4f
> 0x7a  0x33  0x76  0x66  0x75  0x36  0x58  0x56  0x57  0x6e  0x35  0x63
> 0x77  0xa
>
> Plaintext hex:  0xffffffba  0x48  0x32
>
> Plaintext char:  º  H  2
>
> Stephen
>

Reply via email to