[Base64 Decoding] Bug when decoding?? - Openssl

This is a discussion on [Base64 Decoding] Bug when decoding?? - Openssl ; Hi All, I'm trying to decode a Base64 encoded string. Using the openssl decoding command:* echo "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u=" | openssl enc -base64 -d *I got no result! nothing!!! I tried to decode this string on an online base64 decoder ...

+ Reply to Thread
Results 1 to 11 of 11

Thread: [Base64 Decoding] Bug when decoding??

  1. [Base64 Decoding] Bug when decoding??

    Hi All,

    I'm trying to decode a Base64 encoded string. Using the openssl decoding
    command:*

    echo
    "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u="
    | openssl enc -base64 -d

    *I got no result! nothing!!! I tried to decode this string on an online
    base64 decoder http://webnet77.com/cgi-bin/helpers/base-64.pl and it's ok!!
    I have the correct string
    ( wich is an encrypted string). What's wrong with openssl command???

    Thank you for help.

    --
    Karim


  2. Re: [Base64 Decoding] Bug when decoding??

    Hello karim
    The line must be at most 64 octets long
    using the file essai.pem where the unique has been splited in three
    the command

    openssl enc -base64 -d -in essai.pem
    works.

    but be carefull most of the character are not printables

    karim Bendadda a écrit :
    > Hi All,
    >
    > I'm trying to decode a Base64 encoded string. Using the openssl
    > decoding command:/
    >
    > echo
    > "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u="
    > | openssl enc -base64 -d
    >
    > /I got no result! nothing!!! I tried to decode this string on an
    > online base64 decoder http://webnet77.com/cgi-bin/helpers/base-64.pl
    > and it's ok!! I have the correct string
    > ( wich is an encrypted string). What's wrong with openssl command???
    >
    > Thank you for help.
    >
    > --
    > Karim



    --
    Dr Dominique LOHEZ
    ISEN
    41, Bd Vauban
    F59046 LILLE
    France

    Phone : +33 (0)3 20 30 40 71
    Email: Dominique.Lohez@isen.fr

    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  3. Re: [Base64 Decoding] Bug when decoding??

    Hi Dominique,


    First I'd like to thank you for your quick answer. You're right, it
    works well when spliting. I'd like now to do it using the openssl API
    (I found the function above on the web). This function works well for input
    at most 64 bytes .May I have to do a manual split where input is at least 64
    bytes long? Is there any methods (an Openssl function for example) to do it
    automatically???.

    Thank you for your efforts.

    *char *unbase64(unsigned char *input, int length)
    {
    BIO *b64, *bmem;

    char *buffer = (char *)malloc(length);
    memset(buffer, 0, length);

    b64 = BIO_new(BIO_f_base64());
    bmem = BIO_new_mem_buf(input, length);
    bmem = BIO_push(b64, bmem);

    BIO_read(bmem, buffer, length);

    BIO_free_all(bmem);

    return buffer;
    }
    *
    --------------------------------------------------------------------------------------------------------------------------------------
    On Thu, May 22, 2008 at 3:57 PM, Dominique Lohez
    wrote:

    > Hello karim
    > The line must be at most 64 octets long
    > using the file essai.pem where the unique has been splited in three
    > the command
    >
    > openssl enc -base64 -d -in essai.pem
    > works.
    >
    > but be carefull most of the character are not printables
    >
    > karim Bendadda a écrit :
    >
    > Hi All,
    >>
    >> I'm trying to decode a Base64 encoded string. Using the openssl decoding
    >> command:/
    >> echo
    >> "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u="
    >> | openssl enc -base64 -d
    >>
    >> /I got no result! nothing!!! I tried to decode this string on an online
    >> base64 decoder http://webnet77.com/cgi-bin/helpers/base-64.pl and it's
    >> ok!! I have the correct string
    >> ( wich is an encrypted string). What's wrong with openssl command???
    >>
    >> Thank you for help.
    >>
    >> --
    >> Karim
    >>

    >
    >
    > --
    > Dr Dominique LOHEZ
    > ISEN
    > 41, Bd Vauban
    > F59046 LILLE
    > France
    >
    > Phone : +33 (0)3 20 30 40 71
    > Email: Dominique.Lohez@isen.fr
    >
    > __________________________________________________ ____________________
    > OpenSSL Project http://www.openssl.org
    > User Support Mailing List openssl-users@openssl.org
    > Automated List Manager majordomo@openssl.org
    >




    --
    Karim


  4. Re: [Base64 Decoding] Bug when decoding??

    You have to write a loop
    1) extract the 64 first byte from the coded string and copy the to
    a working buffer
    2) convert the working buffer to aat most 48 bytes result buffer
    3) copy the working buffer to the the result
    4) continue with the next 64 byte s of the input string
    karim Bendadda a écrit :
    > Hi Dominique,
    >
    >
    > First I'd like to thank you for your quick answer. You're right,
    > it works well when spliting. I'd like now to do it using the openssl API
    > (I found the function above on the web). This function works well for
    > input at most 64 bytes .May I have to do a manual split where input is
    > at least 64 bytes long? Is there any methods (an Openssl function for
    > example) to do it automatically???.
    >
    > Thank you for your efforts.
    >
    > /char *unbase64(unsigned char *input, int length)
    > {
    > BIO *b64, *bmem;
    >
    > char *buffer = (char *)malloc(length);
    > memset(buffer, 0, length);
    >
    > b64 = BIO_new(BIO_f_base64());
    > bmem = BIO_new_mem_buf(input, length);
    > bmem = BIO_push(b64, bmem);
    >
    > BIO_read(bmem, buffer, length);
    >
    > BIO_free_all(bmem);
    >
    > return buffer;
    > }
    > /
    > ---------------------------------------------------------------------------------------------------------------------------------------
    > On Thu, May 22, 2008 at 3:57 PM, Dominique Lohez
    > > wrote:
    >
    > Hello karim
    > The line must be at most 64 octets long
    > using the file essai.pem where the unique has been splited in three
    > the command
    >
    > openssl enc -base64 -d -in essai.pem
    > works.
    >
    > but be carefull most of the character are not printables
    >
    > karim Bendadda a écrit :
    >
    > Hi All,
    >
    > I'm trying to decode a Base64 encoded string. Using the
    > openssl decoding command:/
    > echo
    > "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u="
    > | openssl enc -base64 -d
    >
    > /I got no result! nothing!!! I tried to decode this string on
    > an online base64 decoder
    > http://webnet77.com/cgi-bin/helpers/base-64.pl and it's ok!!
    > I have the correct string
    > ( wich is an encrypted string). What's wrong with openssl
    > command???
    >
    > Thank you for help.
    >
    > --
    > Karim
    >
    >
    >
    > --
    > Dr Dominique LOHEZ
    > ISEN
    > 41, Bd Vauban
    > F59046 LILLE
    > France
    >
    > Phone : +33 (0)3 20 30 40 71
    > Email: Dominique.Lohez@isen.fr ominique.Lohez@isen.fr>
    >
    > __________________________________________________ ____________________
    > OpenSSL Project http://www.openssl.org
    > User Support Mailing List
    > openssl-users@openssl.org penssl-users@openssl.org>
    > Automated List Manager
    > majordomo@openssl.org
    >
    >
    >
    >
    > --
    > Karim



    --
    Dr Dominique LOHEZ
    ISEN
    41, Bd Vauban
    F59046 LILLE
    France

    Phone : +33 (0)3 20 30 40 71
    Email: Dominique.Lohez@isen.fr

    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  5. Re: [Base64 Decoding] Bug when decoding??

    On Thu, May 22, 2008, karim Bendadda wrote:

    > Hi All,
    >
    > I'm trying to decode a Base64 encoded string. Using the openssl decoding
    > command:*
    >
    > echo
    > "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u="
    > | openssl enc -base64 -d
    >
    > *I got no result! nothing!!! I tried to decode this string on an online
    > base64 decoder http://webnet77.com/cgi-bin/helpers/base-64.pl and it's ok!!
    > I have the correct string
    > ( wich is an encrypted string). What's wrong with openssl command???
    >


    Did you try the -A option?

    Steve.
    --
    Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
    OpenSSL project core developer and freelance consultant.
    Homepage: http://www.drh-consultancy.demon.co.uk
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  6. Re: [Base64 Decoding] Bug when decoding??

    On Thu, May 22, 2008 at 02:20:07PM +0200, karim Bendadda wrote:

    > Hi All,
    >
    > I'm trying to decode a Base64 encoded string. Using the openssl decoding
    > command:*
    >
    > echo
    > "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u="
    > | openssl enc -base64 -d


    The string is too long to fit on one line. The "openssl base64" decoder
    requires long strings to be split over multiple lines. As you can see, the
    limit is 80 characters per-line:

    $ let i=15; while (( i < 25))
    do
    echo $i $(perl -e "printf qq{%s\n}, q{AAAA} x $i" |
    openssl base64 -d | wc -c)
    let i=i+1
    done
    15 45
    16 48
    17 51
    18 54
    19 57
    20 0
    21 0
    22 0
    23 0
    24 0

    Also each line MUST end with "\n" or "\r\n", incomplete last lines don't
    work:

    $ let i=15; while (( i < 25))
    do
    echo $i $(perl -e "printf qq{%s}, q{AAAA} x $i" |
    openssl base64 -d | wc -c)
    let i=i+1
    done
    15 0
    16 0
    17 0
    18 0
    19 0
    20 0
    21 0
    22 0
    23 0
    24 0

    --
    Viktor.
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  7. Re: [Base64 Decoding] Bug when decoding??

    Thanks for examples Victor.

    As Dominique suggests I tried to split the base64 encoded string to blocs.
    The decoding works fine now! but I still have some decrypting
    problems...I'll post my problem on a new topic; it concerning decrypting
    now!.

    Thank you for your help!

    On Thu, May 22, 2008 at 8:14 PM, Victor Duchovni <
    Victor.Duchovni@morganstanley.com> wrote:

    > On Thu, May 22, 2008 at 02:20:07PM +0200, karim Bendadda wrote:
    >
    > > Hi All,
    > >
    > > I'm trying to decode a Base64 encoded string. Using the openssl

    > decoding
    > > command:*
    > >
    > > echo
    > >

    > "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u="
    > > | openssl enc -base64 -d

    >
    > The string is too long to fit on one line. The "openssl base64" decoder
    > requires long strings to be split over multiple lines. As you can see, the
    > limit is 80 characters per-line:
    >
    > $ let i=15; while (( i < 25))
    > do
    > echo $i $(perl -e "printf qq{%s\n}, q{AAAA} x $i" |
    > openssl base64 -d | wc -c)
    > let i=i+1
    > done
    > 15 45
    > 16 48
    > 17 51
    > 18 54
    > 19 57
    > 20 0
    > 21 0
    > 22 0
    > 23 0
    > 24 0
    >
    > Also each line MUST end with "\n" or "\r\n", incomplete last lines don't
    > work:
    >
    > $ let i=15; while (( i < 25))
    > do
    > echo $i $(perl -e "printf qq{%s}, q{AAAA} x $i" |
    > openssl base64 -d | wc -c)
    > let i=i+1
    > done
    > 15 0
    > 16 0
    > 17 0
    > 18 0
    > 19 0
    > 20 0
    > 21 0
    > 22 0
    > 23 0
    > 24 0
    >
    > --
    > Viktor.
    > __________________________________________________ ____________________
    > OpenSSL Project http://www.openssl.org
    > User Support Mailing List openssl-users@openssl.org
    > Automated List Manager majordomo@openssl.org
    >




    --
    Karim


  8. Re: [Base64 Decoding] Bug when decoding??

    Hi Stephen,

    I just try it! it works fine! it doesn't appear when lunching openssl
    command: $openssl enc ?
    How can I implement it using the openssl's EVP API???

    Thank you.

    On Thu, May 22, 2008 at 8:12 PM, Dr. Stephen Henson
    wrote:

    > On Thu, May 22, 2008, karim Bendadda wrote:
    >
    > > Hi All,
    > >
    > > I'm trying to decode a Base64 encoded string. Using the openssl

    > decoding
    > > command:*
    > >
    > > echo
    > >

    > "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPq nSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXlj RolfrSX6bNjcMvfy7k5J+2xo451u="
    > > | openssl enc -base64 -d
    > >
    > > *I got no result! nothing!!! I tried to decode this string on an online
    > > base64 decoder http://webnet77.com/cgi-bin/helpers/base-64.pl and it's

    > ok!!
    > > I have the correct string
    > > ( wich is an encrypted string). What's wrong with openssl command???
    > >

    >
    > Did you try the -A option?
    >
    > Steve.
    > --
    > Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
    > OpenSSL project core developer and freelance consultant.
    > Homepage: http://www.drh-consultancy.demon.co.uk
    > __________________________________________________ ____________________
    > OpenSSL Project http://www.openssl.org
    > User Support Mailing List openssl-users@openssl.org
    > Automated List Manager majordomo@openssl.org
    >




    --
    Karim


  9. [EVP_PKEY] How to duplicate it ?

    Hello everyone,

    I would like to duplicate an EVP_PKEY struct.


    I wrote this not working code:
    BIO *bout = BIO_new(BIO_s_mem());
    PEM_write_bio_PrivateKey(bout, key, NULL, NULL, 0, NULL, NULL);
    key = PEM_read_bio_PrivateKey(bout, NULL, NULL, NULL);
    cout << (key == NULL) << endl;
    BIO_free(bout); //destroy the buffer
    return key;

    Each time, the cout display 1 (key is NULL), i don't know why.

    So is there a way to duplicate it ??
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  10. Re: [Base64 Decoding] Bug when decoding??

    On Fri, May 23, 2008, karim Bendadda wrote:

    > Hi Stephen,
    >
    > I just try it! it works fine! it doesn't appear when lunching openssl
    > command: $openssl enc ?
    > How can I implement it using the openssl's EVP API???
    >


    It is mentioned in the documentation and the BIO equivalent is to set the flag
    BIO_FLAGS_BASE64_NO_NL. See enc and BIO_f_base64() documents. I don't normally
    use EVP for base64 encoding, I use a bio chain so don't know about that.

    Steve.
    --
    Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
    OpenSSL project core developer and freelance consultant.
    Homepage: http://www.drh-consultancy.demon.co.uk
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  11. Re: [EVP_PKEY] How to duplicate it ?

    In message <4836826E.7030506@elodig.fr> on Fri, 23 May 2008 10:38:06 +0200, "delcour.pierre" said:

    pierre.delcour> I wrote this not working code:
    pierre.delcour> BIO *bout = BIO_new(BIO_s_mem());
    pierre.delcour> PEM_write_bio_PrivateKey(bout, key, NULL, NULL, 0, NULL, NULL);
    pierre.delcour> key = PEM_read_bio_PrivateKey(bout, NULL, NULL, NULL);
    pierre.delcour> cout << (key == NULL) << endl;
    pierre.delcour> BIO_free(bout); //destroy the buffer
    pierre.delcour> return key;
    pierre.delcour>
    pierre.delcour> Each time, the cout display 1 (key is NULL), i don't know why.

    From pem.pod:

    The read routines return either a pointer to the structure read or NULL
    if an error occurred.

    So apparently, an error occured. To display it, do the following
    (requires stdio):

    ERR_print_errors_fp(stderr);

    Cheers,
    Richard

    -----
    Please consider sponsoring my work on free software.
    See http://www.free.lp.se/sponsoring.html for details.

    --
    Richard Levitte richard@levitte.org
    http://richard.levitte.org/

    "When I became a man I put away childish things, including
    the fear of childishness and the desire to be very grown up."
    -- C.S. Lewis
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


+ Reply to Thread