Ahmed Samy
Ahmed Samy

Reputation: 1046

Can I decode data with base64 in php which was encoded in java?

I have this java code I used to encode a serialized object that contains a couple of strings in base64

public static String encode(Object obj) throws IOException {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    ObjectOutputStream o = new ObjectOutputStream(b);
    o.writeObject(obj);
    return Base64.encodeToString(b.toByteArray(), Base64.DEFAULT);
}

I store the resultant string in database using PHP ... I know how to decode this in java but for some reasons I need to do it in the PHP code ... so how to do it in PHP ?

Upvotes: 1

Views: 1115

Answers (1)

RockOnGom
RockOnGom

Reputation: 3961

Base64 is an encoding scheme, so it doesn't matter which language you use when you encode or decode.

 <?php
    $str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';//your base64 encoded string
    echo base64_decode($str);
 ?>

Upvotes: 1

Related Questions