0

After decrypting the string using private key, using echo returns value. But when i try to base64_decode its returning null. I needed the value for base64_decode.

openssl_private_decrypt(base64_decode($_POST['data']), $data, $privateKey, OPENSSL_NO_PADDING);

echo $data; // Returning Value --> k/HgB3uQZ1klyeHlJ2jhcG5fSOy+GowIF4bich195ll7zNF9sQbgg/1MkiUpk4ScFlT2e0XIwXzANGgrNi2yEg==
echo base64_decode($data); // returning null
jww
  • 97,681
  • 90
  • 411
  • 885
vijay
  • 46
  • 10
  • `echo $data; echo base64_decode($_POST['data']);` – Akam May 28 '16 at 14:13
  • Possible duplicate of [Print $\_POST variable name along with value](http://stackoverflow.com/questions/3489387/print-post-variable-name-along-with-value) – jww May 28 '16 at 18:12

2 Answers2

1

Base64 decoding the string:

k/HgB3uQZ1klyeHlJ2jhcG5fSOy+GowIF4bich195ll7zNF9sQbgg/1MkiUpk4ScFlT2e0XIwXzANGgrNi2yEg==

The decoded Base64, it is binary data not a string:

93F1E0077B90675925C9E1E52768E1706E5F48ECBE1A8C081786E2721D7DE6597BCCD17DB106E083FD4C92252993849C1654F67B45C8C17CC034682B362DB212

In general binary data can not be represented in printable characters and in most cases can not be represented in any character set.

zaph
  • 111,848
  • 21
  • 189
  • 228
0

Your String might contain a line break '\n' or some other character that is not decodable in base64, try removing line breaks by using:

str_replace(array("\r", "\n"), '', $data);

(Source: How to remove line breaks (no characters!) from the string?)

Community
  • 1
  • 1
bbasti
  • 31
  • 5