Base64 encoded string differs in perl and Java -


when encode pdf file base64 binary(using commons lib) in java , got string(sample) "sgvsbg8gv_29y-bgq="

but if encode same file using perl , got "sgvsbg8gv/29y+bgq="

difference in string: / instead of _ , + instead of -

why getting this? or, there way fix without string replace ?

in java

byte[] data;         try (java.io.fileinputstream fin = new java.io.fileinputstream(new java.io.file("file.pdf"))) {             data = new byte[fin.available()];             fin.read(data);         }         return data; system.out.println("ecncoded value " + datatypeconverter.printbase64binary(data)); 

in perl

use mime::base64;  open (pdf, "file.pdf") or die "$!";  $raw_string = do{ local $/ = undef; <pdf>; }; $encoded = encode_base64( $raw_string );  print " \n"; print " $encoded "; 

// java

enter image description here

// perl

enter image description here

the java code giving url-safe base64, i.e output can used in urls. perl version not. can blindly replace characters other values.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -