Category Archives: base64

base64 image not displaying

I am using Grégoire's PHP Captcha library, on local host, it is working fine, as of creating images, and sending to browser. But when same code is on remote server, Captcha Image is not being displayed client side. Since in both cases each image request is responded with around 20kB of data, I am sure the image is being downloaded. And from the looks of it, it seems a valid base64 of an image. the only difference I have noticed is that when logging the base64 string, it is usually shorter, around 8kB, while the base64 from localhost is just as much as the real image, ~20kB. But with my knowledge, I don't know how to use this information. Any Guidelines?

snippet of code:

$captcha = new Gregwar\Captcha\CaptchaBuilder;
$captcha->build(
Config::get('CAPTCHA_WIDTH'),
    Config::get('CAPTCHA_HEIGHT')
);
header('Content-type: image/jpeg');
$captcha->output();

Further Info:

I have used wamp on my windows 7, but installed apache2, php5 separately on remote ubuntu 14.04.

Localhost: apache 2.4.9 , php 5.5.12

Remote Server: apache 2.4.7 , php 5.5.9

In both cases No error is being generated whatsoever.

a working base64 from localhost:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPU ... iiigAooooAKKKKACiiigD//2Q==

which is usually around 20 kbytes long.

a not-working base64 from remote server:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPU ... I0vQ7A

which is usually around 8 kbytes long.

Base64 encode and decode not give same result

I have been banging my head against a wall on this all day. I have a PDF file that we generate. The PDF file looks fine in Acrobat.

I need to encode the file in base64. Using Apache codec library I do this:

String base64buf = Base64.encodeBase64String( m_reportText.getBytes( "UTF-8" ) );

As a test I write base64buf out to a file:

Files.write( new File( "report.b64" ).toPath(), base64buf.getBytes( "UTF-8") );

Then I convert it back, just to see if it is working:

String encodedName = "report.b64";
String decodedName = "report.pdf";

// Read original file.
byte[] encodedBuffer = Files.readAllBytes( new File( encodedName ).toPath() );

// Decode
byte[] decodedBuffer = Base64.decodeBase64( encodedBuffer );

// Write out decodedBuffer.
FileOutputStream outputStream = new FileOutputStream( decodedName );
outputStream.write( decodedBuffer );
outputStream.close();

I open report.pdf in Acrobat and it is a blank document. It has the correct number of pages (all are blank).

What am I missing here?

Base64 encode and decode not give same result

I have been banging my head against a wall on this all day. I have a PDF file that we generate. The PDF file looks fine in Acrobat.

I need to encode the file in base64. Using Apache codec library I do this:

String base64buf = Base64.encodeBase64String( m_reportText.getBytes( "UTF-8" ) );

As a test I write base64buf out to a file:

Files.write( new File( "report.b64" ).toPath(), base64buf.getBytes( "UTF-8") );

Then I convert it back, just to see if it is working:

String encodedName = "report.b64";
String decodedName = "report.pdf";

// Read original file.
byte[] encodedBuffer = Files.readAllBytes( new File( encodedName ).toPath() );

// Decode
byte[] decodedBuffer = Base64.decodeBase64( encodedBuffer );

// Write out decodedBuffer.
FileOutputStream outputStream = new FileOutputStream( decodedName );
outputStream.write( decodedBuffer );
outputStream.close();

I open report.pdf in Acrobat and it is a blank document. It has the correct number of pages (all are blank).

What am I missing here?

php post request sending base64 image removes some special characters

I have a base64 image. 1) I send it to a php script via ajax post request

$.post('controllers/tlp.php',{endpoint:'myendpoint',params:'img=blahblah'}

2) Php script sends it to a java backend via POST yet again

 curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
 $response = curl_exec($ch);

3) Apache reverse proxy takes the request and sends it to a Java backend.

By the time it reaches the backend, all "+" characters get removed.

The Base64 image is already URLencoded from javascript. So why would this happen?

This works fine if I use a REST client and send the image directly to java backend bypassing php and apache reverse proxy

Any help will be appreciated. Thanks!

How to rewrite url-encoded-base64 with .htaccess

I have used timthumb to resize images from external site. I would like rewrite url to security my site But I don't know how to do it with .htaccess and php

(1) htp://mydomain.com/timthumb.php?src=htp://any-images.jpg&h=70&w=70&zc=1

(2) htp://mydomain.com/70/70/aHR0cDovL2ltYWdlc2hhY2suY29tL2EvaW1nOTEyLzE4NTgvZ3Z

I used php encode base64 htp://any-images.jpg to aHR0cDovL2ltYWdlc2hhY2suY29tL2EvaW1nOTEyLzE4NTgvZ3Z

Now the question is: How to do rewrite from (1) to (2)?

Base64 decoder not working in apache [on hold]

I'm trying to decode a string using Base64. I tried on my local machine and it give successfull results but when I upload a war file in the server apache tomcat 6.0 it gives an error in initializing Base64 class.

log.debug("before dycrypt");
        Cipher cipher = getCipher(ALGORITHM, Cipher.DECRYPT_MODE, keystorePassword);
        log.debug("before base init");
        BASE64Decoder decoder = new BASE64Decoder();
        log.debug("before do final");
        byte[] decrypted = cipher.doFinal(decoder.decodeBuffer(password));
        log.debug("after dycrypt");
        return new String(decrypted, "UTF-8");

Can anyone help with these?? I have included a library in build path and working fine on locally.

Apache codec base64 encode/decode – not getting expected result

I did a POC using apache codec base64 library, where I encrypted a string using SHA. (This can be ignored).

Step 1 - I printed byte array for that string.

Step 2 - Encoded the byte array and printed its value.

Step 3 - Decoded the encoded value and printed it.

public static void main(String[] args)
{
    MessageDigest messageDigest = null;
    String ALGORITHM = "SHA";
    try
    {
        messageDigest = MessageDigest.getInstance(ALGORITHM);

        byte[] arr = "admin1!".getBytes();
        byte[] arr2 = messageDigest.digest(arr);

        System.out.println(arr2);
        String encoded = Base64.encodeBase64String(arr2);

        System.out.println(encoded);
        byte[] decoded = Base64.decodeBase64(encoded);

        System.out.println(decoded);
    }
    catch (NoSuchAlgorithmException e)
    {
        e.printStackTrace();
    }
}

Expected result : Step 1 and Step 3 should produce same output. But I am not getting that.

Output :

[[email protected]

90HMfRqqpfwRJge0anZat98BTdI=

[[email protected]

Htaccess Rewrite Seo Friendly [on hold]

if i having a link structure lets say like this?

http:// www.domain.com/out.php?link=images/5x11x478554&order=ctr&url=http://www.domain.com/gallery/test-test/index.html

how can i use .htaccess to make it SEO friendly using a decryption like base64 so it would be:

http:// www.domain.com/go.php?track=( dfafadfoijfiafj )&url=http://www.domain.com/gallery/test-test/index.html

where dfafadfoijfiafj is the part of images/5x11x478554&order=ctr

thanks for ya help:)