Base64 encode and decode

Hello

I use opennssl for encoding and decoding base 64 and face to face some of the question, he refuses to randomly to encode or decode, to give me a result of 0 and not false BIO_SHOULD_RETRY... I'm trying to put the call in a while if return 0, but it does not work and so I can not decode or encode more...

The code I am using:

uint8_t* Tools::base64(uint8_t *input,  uint32_t length)
{
        BIO *bmem, *b64;
        BUF_MEM *bptr;

        b64 = BIO_new(BIO_f_base64());
        BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
        bmem = BIO_new(BIO_s_mem());
        b64 = BIO_push(b64, bmem);

        // write data
    bool done = false;
    int res = 0;
    while(!done)
    {
        res = BIO_write(b64, input, length);

        if(res <= 0) // if failed
        {
            if(BIO_should_retry(b64)){
                continue;
            }
            else // encoding failed
            {

                qDebug("error while encoding base64");
                done=true;
            }
        }
        else // success!
            done = true;
    }

     //   BIO_write(b64, input, length);
        BIO_flush(b64);
        BIO_get_mem_ptr(b64, &bptr);

        uint8_t *buff = (uint8_t *)malloc((bptr->length)+1);
        memcpy(buff, bptr->data, bptr->length);
        buff[bptr->length] = 0;

        BIO_free_all(b64);

        return buff;
}

uint32_t Tools::decode64(uint8_t *pInput, uint32_t inputLen, uint8_t ** ppOutput)
{
        BIO *b64, *bmem;
        uint32_t readLen;

        (*ppOutput) = (uint8_t *)malloc(inputLen);
        memset((*ppOutput), 0, inputLen);

        b64 = BIO_new(BIO_f_base64());
        BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
        bmem = BIO_new_mem_buf(pInput, inputLen);
        bmem = BIO_push(b64, bmem);

        // write data
    bool done = false;

    while(!done)
    {
          readLen = BIO_read(bmem, (*ppOutput), inputLen);

        if(readLen <= 0) // if failed
        {
            if(BIO_should_retry(b64)){
                continue;
            }
            else // encoding failed
            {

                qDebug("error while decoding base64");
                /*int reason;
                BIO_get_retry_BIO(b64,&reason);
                qDebug() << "reason of bio bug " << reason;*/

                //dont know what to do ;-(
                done=true;
            }
        }
        else // success!
            done = true;
    }

        BIO_free_all(bmem);

        return readLen;
}

If you have ideas do not hesitate to discuss it!

Thanks in advance!

Try http://qt-project.org/doc/qt-4.8/qbytearray.html#toBase64

Tags: BlackBerry Developers

Similar Questions

  • memory encoding and decoding

    Hi, I'm working on the project now.

    I use a program that someone else created and change to the new PDA device that is enough for us.

    I need to understand how the programmer coded the old way for me so to unstanding how interpetted the code registers 8 memory.

    well, from stractch...

    This give PDA code 8 memory registers...

    I think they are hex and his converts to binary.

    There are 26 bits...

    the code I will attach take these bits and decode out them...

    I don't understand what is happening in this code, so I was hoping that someone can help me by disabling things for.

    Propably you can connect the inputs/outputs (or read/write for the globals) of the vi decodeing and then boning with these data.

    Felix

  • The URL encoding and decoding in OSB

    Hello

    Do we not have out-of-box solution in OSB decode XML that is encoded in URL and encode XML to the URL encoding. If yes how can I do.

    It is perhaps a fundamental question. I can't understand. New on OSB.

    Thank you
    Sham.

    encode an XML to URL encoding format

    No function out of the box I know, I think that you will need a legend of Java to do... I was wondering why you need that...

    It's the doc... Adding and configuring Actions of legend of Java in the stream of messages
    http://docs.Oracle.com/CD/E23943_01/dev.1111/e15866/tasks.htm#OSBDV164

    See you soon,.
    Vlad

    It is considered good etiquette to the answerers rewards with points (as "useful" - 5 pts - or 'correct' - 10pts)
    https://forums.Oracle.com/forums/Ann.jspa?annID=893

  • Coding and decoding

    Hello
    I need to send data to a server, I have encrypt the data, but I'm not able to send the encrypted data on the server. Do I need to encode the data, if so, then tell me how,

    How can encode us / decode in blackberry, my data is a simple string.

    First, choose a common algorithm that works on the side and the help that you can encrypt and decrypt. You can google for algo and serach on this forum for similar discussions.

  • Problem with my Base64 Encoding Routine CLOB.

    I wrote a program that reads an xml file in the database
    and makes Base64encoded.

    We must work on 10g and above

    If the length specified in the code below reading is greater than the length of the xml_file, and then I get the result (output) expected.

    However if the playback time is less than the length of the file, then I get a lot of "is" in the file and, therefore, invalid, which means that the file is not readable by the application of encoding.
    I'm sure I read the lengths of blob correctly, and the problem is somehow related to base64 encoding. Any help appreciated
    [create or replace profile_dir as &profile_dir;
    create global temporary table load_xml
    (profile_text clob)
    on commit delete rows;
    
    create or replace
    procedure encode_xml_clobs(p_file_in  in varchar2,
                                 p_clob_out out nocopy clob )
     as
     pragma autonomous_transaction;
        dest_clob   CLOB;
        src_clob    BFILE  := BFILENAME('PROFILE_DIR', p_file_in);
        dst_offset  number := 1 ;
        src_offset  number := 1 ;
        lang_ctx    number := DBMS_LOB.DEFAULT_LANG_CTX;
        warning     number;
    ------------
    -- processing declarations for encoding base64 --
    v_xml_string varchar2(32767);
    v_string varchar2(32767);
    v_start_pos number := 0;
    v_read_length number := 1000;
    v_final_start_pos number;
    v_clob_length number;
    type clob_array_type is table of clob index by binary_integer;
    clob_array clob_array_type;
    v_index number :=0;
    -- Declarations for converting base64encoded string to a clob
    v_encoded_length number;
    v_temp_clob clob;
    BEGIN
        -- -----------------------------------------------------------------------
        -- THE FOLLOWING BLOCK OF CODE WILL ATTEMPT TO INSERT / WRITE THE CONTENTS
        -- OF AN XML FILE TO A CLOB COLUMN. IN THIS CASE, WE WILL USE THE NEW 
        -- DBMS_LOB.LoadCLOBFromFile() API WHICH *DOES* SUPPORT MULTI-BYTE
        -- CHARACTER SET DATA.
        -- -----------------------------------------------------------------------
    -- load_xml should be a  Global temporary table with on commit delete rows 
        INSERT INTO load_xml(profile_text) 
            VALUES( empty_clob())
            RETURNING profile_text INTO dest_clob;
    
        -- -------------------------------------
        -- OPENING THE SOURCE BFILE IS MANDATORY
        -- -------------------------------------
        DBMS_LOB.OPEN(src_clob, DBMS_LOB.LOB_READONLY);
    
        DBMS_LOB.LoadCLOBFromFile(
              DEST_LOB     => dest_clob
            , SRC_BFILE    => src_clob
            , AMOUNT       => DBMS_LOB.GETLENGTH(src_clob)
            , DEST_OFFSET  => dst_offset
            , SRC_OFFSET   => src_offset
            , BFILE_CSID   => DBMS_LOB.DEFAULT_CSID
            , LANG_CONTEXT => lang_ctx
            , WARNING      => warning
        );
        DBMS_LOB.CLOSE(src_clob);
    --    DBMS_OUTPUT.PUT_LINE('Loaded XML File using DBMS_LOB.LoadCLOBFromFile: (ID=1');
    -- file now successfully loaded
    
    select dbms_lob.GETLENGTH(profile_text)
    into v_clob_length 
    from load_xml;
    -- File now loaded in temporary table
    -- we now need to take the clob , convert it to varchar2
    v_read_length :=64;
    v_xml_string := '';
    while v_start_pos <=  v_clob_length
    loop
    v_index := v_index + 1;
    v_string := '';
    --dbms_output.put_line('Start_pos=>'||(v_start_pos+1)||' Read Length=>'||v_read_length);
    --encode base64 
    select utl_raw.cast_to_varchar2(
    utl_encode.base64_encode(
    utl_raw.cast_to_raw(dbms_lob.substr(profile_text,least(v_read_length,v_clob_length-v_start_pos),v_start_pos+1))
    ))
      into v_string
      from load_xml;
    --dbms_output.put_line(v_string);
    v_start_pos  := v_start_pos+v_read_length;
    clob_array(v_index) := v_string;
    end loop;
    p_clob_out := clob_array(1);
    for i in 2 .. v_index
    loop
    dbms_lob.append(p_clob_out,clob_array(i));
    end loop;
    commit;
    END;

    Base64 encoding encodes each 3 bytes of input data in the 4 bytes of output data. She uses the equal signs to indicate nodata and at the end of the coded sequence. Try chaning your v_read_length setting to a multiple of 3 e.g. 960 or 1008 instead of the current 1000. I use multiples of 48 because the utl_encode.base64_encode function adds a linebreak for every 48 bytes of input data (64 bytes of output). If you use a value that is not divisible by 48, you will always get a legitimate coding, since it is divisible by 3, but you'll get a few lines more than others when you add them together.

  • Double retroactive loop via an encoder and a tachometer

    I'm building a human rotating Chair for research purposes and want to use a double retrospective loop to remove the backslash. The current system, however, includes only 1 Encoder on load (President) and 1 tachometer and the engine due to the geometry of the system, I can not put an extra Encoder on the motor. I would like to know if there is a controller of axes OR which may take a signal encoder and tachometer signal (speed - analog signal) to close the double loop retroactive.

    Please refer to the attachment for the functional diagram of the system.

    Thanks for any help.

    Hi Ron,

    Based on your schema, I don't see a way to do - are you willing to do all the control without firing the values in LabVIEW?  If so, then I don't see a way to do this.  If you pull the tach values in LabVIEW, you have more options, but none is as complete, having a second encoder.

    All movement PCI cards offer analog inputs, so that you could potentially play in the tachometer signal.  However, what kind of signal it is up?  If its RPM, there is a bit of calculation to actually determine the velocity and I worry not with that many steps in the software, you will kill any 'control loop price' that you may have.  I don't think that the system would be too sensitive if you have to shoot these values in the software; and unfortunately it is not "currently a movement card that reads these signals directly."

    I hope this helps.

    Marti

  • Retrigger encoder and acquisition of analog input on the spur of Z?

    I have a card PCI-6232 and use THIS angular Encoder on the counter 1 to provide a base mean angle for Internet high speed (50-100 kHz) measures the analog voltage.  I use a period of CI on counter 2 to measure the duration of the impulse of Z to determine the length of each measure.  It kinda works, but the result is somewhat contradictory.  I get about 1 in three cycles without encoder data.  I need to find a way to trigger the acquisition to record data for each cycle trigger on the pulse of Z.  If you know another way to do this I'd be open to that as well.  Thank you, Steve

    Hi Sara,.

    Thanks for your reply.  What I wanted to do was to trigger an analysis of the encoder and an entry at the same time triggering the pulse of z analog encoder.  It took a lot of digging through similar samples and after a week of fighting, I thought about it tonight.  I'll post this once I clean up the mess.  Problem solved thanks to dozens of you ad info and samples!

  • Creating Windows Dvd encodes and burns, but the dvd is blank.

    * - Original title - when I put my movie in Windows Dvd Maker, it encodes and burns.

    . But when he ejects itself there is nothing on the disc it just says: disc... Why - what is happening to you, it has worked well in the past. Using Windows 7 please help?

    Hello

    1. What is the type of file that you burn in the disk?

    2. have you made changes on the computer recently?

    3. are you able to burn the disc using any third party CD or DVD burning software?

    Once you get a message that the burning is complete, check the size of the free space and space used on the DVD.

    For information about how to check the user-space and the free space, you need to right click on the DVD drive, and then click Properties.

    Well, it seems that when you burn a CD or DVD, the disc is not finalized.

    For reference.
    Close or finalize a CD or DVD
    http://Windows.Microsoft.com/en-us/Windows7/close-or-finalize-a-CD-or-DVD

    Burn a DVD-video using Windows DVD Maker disc: http://windows.microsoft.com/en-US/windows7/Burn-a-DVD-Video-disc-with-Windows-DVD-Maker

    I hope this helps.

  • Y at - it a fix for leak of VRAM in Windows Desktop? (Windows media Encoder and photo IE10 Viewer are the root of the problem)

    It seems that Windows media Encoder and photo IE10 Viewer are the root of the problem, and it is about the whole MS Platform in desktop for what anyone associated media.  As easy as it is to use another browser or image viewer I find I like the windows photo viewer ability to preview multiple images and IE10 and 11 are more now then fix everything that exists.

    The issue is having to restart or log out and back in just pass leak VRAM that can go up to 1400 MB and count. What said GPU - Z and ESTR.  The memory of the system seems to be in check most of the time.  Get off my GPU memory Windows.

    I mean leak even with the left running only windows desktop and essential tasks to keep it that way.  I have games that will never saturate 1.5 GB of video memory on my setup. Darn Far Cry 3 does not work.   I'm ranting, namely. At the same time being a little in-depth play play of this recurring problem.

    In case the VP and general manager or anyone else to Microsoft is approaching through it all here is the short version:

    Video memory leak in Windows 8. How can I fix this in the Windows desktop. Is there a way to erase the GPU cache and reduce the use VRAM 160MO? is there a fix? is there a value from regedit?

    Hey Marv,

    Thanks for posting your query in Microsoft Community Forum.

    According to the description of the issue, I recommend you post your query in the TechNet Forums. TechNet is watched by other computing professionals who would be more likely to help you.

    TechNet Forum

    http://social.technet.Microsoft.com/forums/Windows/en-us/home?category=W8

    Hope this information is useful.

  • I have the Prime Minister but not encoder and im trying to export videois to how put it on dvd

    I have the Prime Minister but not encoder and im trying to export videois to how put it on dvd

    You must follow the instructions to download/install Encore DVD creating program, as long as the content of the library and put in place so that when you open it, you have all the stuff to work.

    Article download/install Adobe Encore:

    https://helpx.Adobe.com/Encore/KB/Encore-CS6-installed-cc.html

    http://helpx.Adobe.com/Encore/using/download-library-content.html

    Neil

  • I get errors after effects CC 2015, Media Encoder, and also Cineware

    Hello

    I have problems with 2 things.  First of all, when I try to go to Adobe Media Encoder I get the following error:

    after effects media encoder error.PNGafter effects media encoder error2.PNG

    It works perfectly well first Pro CC.  If I open Media encode and import a legacy file that works fine as well.

    And when I try to create new cinema 4 D file:

    after effects cineware error.PNG

    There is NO movie theater that installed 4 d I can see on my system - where it is and how to download?  I tried to use import Photoshop 3D, but apparently we cannot do that more with CC?

    System: Windows 7

    Thanks in advance

    Dave

    The update fixes after effects CC 2015 (13.5.1) and Adobe Media Encoder CC 2015 (9.0.1) update are available: http://adobe.ly/1Il5JYe

  • Where are still, Media Encoder and bridge?

    I am owner of a CS6 who just signed up for creative cloud.  I go to the installation page and don't see apps for Adobe Encore, Media Encoder and bridge?  Does this mean that my versions of the apps need to be modernized, or that one or more of them could be discontinued moving forward (surely not Media Encoder!)?

    Adobe still isn't available sepratelly fine install with Prime Pro CS6 family.

    Media Encoder is also not available sepratelly it will install with software video editing as first pro and After Effect.

    Bridge is used with a lot of application to edit images and create betwwen bridge applications and is not available sepretlly. It is available with apps like Photoshop, After effects, etc.

  • encoding and export of text (JS CS3 MAC and PC)

    Hi - I'm trying to export text in InDesign as an ASCII file. But I end up with a file of zero K.

    myX var = new File (myTarget);

    myX.encoding = "ASCII";

    myX.lineFeed = "unix";

    myX.open ("w");

    myX.write (myString);

    myX.close ();

    I have success with this:

    myX var = new File (myTarget);

    myX.encoding = "UTF-8";

    myX.lineFeed = "unix";

    myX.open ("w");

    myX.write ("\uFEFF" + myString);

    myX.close ();

    But the person at the other end of the export, says I need to convert UTF - 8 coding ASCII.

    Any help would be greatly appreciated.

    My bad! I knew that U + FFFD might appear occasionally in straight copied text out of InDesign, so I checked his UTF8 encoding and it's 'EF BB BF. That's why I thought that you are deceived and recommended to remove U + FFFD.

    But... you're right after all. One tells you it's, "EF BB BF", also translates into yet another code ID use as a "placeholder": U + FEFF, and since it is also a special code in Unicode your customer has problems with it.

    Change the line of replacement to it (this time around, I made sure to run your script and check the result before posting...).

    myString = myString.replace (/ \uFEFF/g, "");

  • SQL Loader: Help TRIM and Decode functions please

    Hello

    I have load data from a flat file, for some columns, I need to use the TRIM and DECODE functions. It's a pipe delimited file.

    I get a syntax error (one is lower) same error listed for GARNISH.

    SQL * Loader-350: at line xx syntax error.
    Expected ', 'or') ', found 'DECODE '.


    ===========
    , FINAL_BILL_DATE CHAR (30) "TRIM(:FINAL_BILL_DATE)".
    , BUSINESS_ID 'DECODE(:BUSINESS_ID,'B',1,'C',2,'E',3,'G',4,'O',5,'R',6,'T',7,'U',8,'H',9,-1) '.


    Can someone please help.

    Thank you
    Josiane

    Hello josiane.
    The error you receive leads me to believe that at some point before the DECODING on the BUSINESS_ID line, probably some line before the FINAL_BILL_DATE line, it is a syntactic error causing the quotes before DECODING actually put an end to some other syntaxes. Without any lines that might actually contribute to this, including details of the header, it's the best I can advise.

    Hope this helps,
    Luke

    Please check the answer as helpful or response, if it is so. If this is not the case, further clarification.
    Try to always provide create table and table insert to help members of the forum to help you.

  • Problem with encoding and setUrl() automatic percentage incomplete

    OK, I have this for Oauth method:

    Petición QNetworkRequest = QNetworkRequest();

    peticion.setUrl(QString(oa_url+oa_callback+callback+oa_consumerKey+consumerKey+oa_nonce+nonceGenerate+oa_signature+signature+oa_signatureMethod+signatureMethod+oa_timestamp+timestampGenerate+oa_version+oauthVersion));

    All values are OK, but when my base64 signature throw '+' sign setUrl() function don't this encoded to % 2B. So if I move to the firm as a percentEncoded() (this function if it fills completely) setUrl() makes me sign '%' % 25 and the server throws me an error signature. How can I fix?

    Understand the problem?

    Solution for this:

    Make POST request.

    Do not GET to ask, as QUrl or coded setUrl BAD your signature base 64!

Maybe you are looking for

  • C4795 HP printer does not print in the browser firefox, but in IE

    I have a printer HP C4795 and HP windows 7 and the printer will not work with firefox. It works fine in IE. I had trouble with firefox crashing yesterday so I uninstalled and reinstalled and printer does not work. has worked in firefox before my test

  • Send Fax from PC to HP Officejet 4500 all-in-One G510

    When I print to fax printer HP Officejet 4500 G510g-m, no sending a Fax screen opens asking the fax information. It goes directly to the print queue and justs sits there saying print.  Fax works OK when sending the fax paper through the machine. This

  • Win7pro update download does not start

    win7pro. Download ISO update does not work in the browser without stop with the second window asking open/save/Cancel. by clicking on 'Open' start the Browse button, and then stops and same window starts again. I tried fresh download and still no. Id

  • For a HPLJ 200 pro color MFP admin password problem

    I forgot the password admin for my HPLJ 200 pro color MFP, please help

  • Can't make contacts lists in Windows mail.

    I recently bought a new computer with Vista and windows mail. I want to set up lists of contacts for email but couldn't find 'new contact group' on the contact toolbar (as described in help "in the toolbar, click New Contact Group, type a name in the