Blowfish crypto messes up first 8 bytes during encryption and decryption

LocalToast

I just tried out some en-/decryption with the openssl c librarys blowfish algorithm and ran into an odd error: the first 64 bits of the decrypted message are somehow messed up.

What am I doing wrong?

Here is the code:

#include <openssl/blowfish.h>
#include <cstring>
#include <cstdio>

int main()
{
    unsigned char rawKey[] = "password";

    BF_KEY key;
    BF_set_key(&key, strlen((char*) rawKey), rawKey);

    unsigned char msg[] = "Lorem ipsum dolor sit amet";

    unsigned char enc[64];
    memset(enc, 0, 64);
    unsigned char ivec[8];
    memset(ivec, 0, 8);

    BF_cbc_encrypt(msg, enc, strlen((char*) msg) + 1, &key, ivec,
        BF_ENCRYPT);

    unsigned char dec[64];

    BF_cbc_encrypt(enc, dec, strlen((char*) msg) + 1, &key, ivec,
        BF_DECRYPT);

    printf("%s\n", dec);

    return 0;
}

The output is:

.,�s�Ksum dolor sit amet

0x7fffffffde20: 46 '.'  3 '\003'    23 '\027'   44 ','  -102 '\232' 115 's' -2 '\376'   75 'K'
0x7fffffffde28: 115 's' 117 'u' 109 'm' 32 ' '  100 'd' 111 'o' 108 'l' 111 'o'
0x7fffffffde30: 114 'r' 32 ' '  115 's' 105 'i' 116 't' 32 ' '  97 'a'  109 'm'
0x7fffffffde38: 101 'e' 116 't' 0 '\000'

Thanks in advance :D !

Defter

Try memset(ivec, 0, 8) before BF_cbc_encrypt. BF_cbc_encrypt maybe change it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Blowfish crypto messes up first 8 bytes during encryption and decryption

From Dev

Blowfish encryption and decryption across c sockets

From Dev

AES Encryption - Encryption/Decryption Adding Extra Bytes

From Dev

Need Help to convert Encryption Blowfish php to Nodejs using crypto

From Dev

Compatibility between node crypto and crypto-js encryption and decryption

From Dev

Java - 2 Bytes character encryption via BlowFish cipher

From Dev

Nodejs Crypto decrypt fails after one successful encryption and decryption

From Dev

.NET AES decryption breaks first few bytes

From Dev

.NET AES decryption breaks first few bytes

From Dev

Encryption & Decryption

From Dev

Encryption & Decryption

From Dev

javax.crypto.BadPaddingException error during AES encryption

From Dev

javax.crypto.BadPaddingException error during AES encryption

From Dev

Crypto Encryption

From Dev

Setting display:none to cell on first row messes up table layout

From Dev

javax.crypto.BadPaddingException: Decryption error when using Java RSA encryption

From Dev

Slow AES GCM encryption and decryption with Java 8u20

From Dev

RC4 Encryption and decryption in UTF-8 ASP classic

From Dev

Blowfish encryption with custom salt in Java

From Dev

Blowfish file encryption without keygenerator

From Dev

md5 encryption and decryption java unable to encrypt more than 16bytes

From Dev

AirPlay messes up localhost

From Dev

Cocoa messes path up?

From Dev

Cocoa messes path up?

From Dev

Perforce messes up symlinks

From Dev

How to handle BadPaddingException During AES256 encryption in C# and decryption in Java

From Java

Encryption with PHP and Decryption with Coldfusion

From Dev

Encryption in JavaScript and decryption with PHP

From Dev

performance on encryption and decryption

Related Related

  1. 1

    Blowfish crypto messes up first 8 bytes during encryption and decryption

  2. 2

    Blowfish encryption and decryption across c sockets

  3. 3

    AES Encryption - Encryption/Decryption Adding Extra Bytes

  4. 4

    Need Help to convert Encryption Blowfish php to Nodejs using crypto

  5. 5

    Compatibility between node crypto and crypto-js encryption and decryption

  6. 6

    Java - 2 Bytes character encryption via BlowFish cipher

  7. 7

    Nodejs Crypto decrypt fails after one successful encryption and decryption

  8. 8

    .NET AES decryption breaks first few bytes

  9. 9

    .NET AES decryption breaks first few bytes

  10. 10

    Encryption & Decryption

  11. 11

    Encryption & Decryption

  12. 12

    javax.crypto.BadPaddingException error during AES encryption

  13. 13

    javax.crypto.BadPaddingException error during AES encryption

  14. 14

    Crypto Encryption

  15. 15

    Setting display:none to cell on first row messes up table layout

  16. 16

    javax.crypto.BadPaddingException: Decryption error when using Java RSA encryption

  17. 17

    Slow AES GCM encryption and decryption with Java 8u20

  18. 18

    RC4 Encryption and decryption in UTF-8 ASP classic

  19. 19

    Blowfish encryption with custom salt in Java

  20. 20

    Blowfish file encryption without keygenerator

  21. 21

    md5 encryption and decryption java unable to encrypt more than 16bytes

  22. 22

    AirPlay messes up localhost

  23. 23

    Cocoa messes path up?

  24. 24

    Cocoa messes path up?

  25. 25

    Perforce messes up symlinks

  26. 26

    How to handle BadPaddingException During AES256 encryption in C# and decryption in Java

  27. 27

    Encryption with PHP and Decryption with Coldfusion

  28. 28

    Encryption in JavaScript and decryption with PHP

  29. 29

    performance on encryption and decryption

HotTag

Archive