I am using PHP openssl_sign to create a digital signature using the tutorial here. How can i convert $signature (which contains binary data) to Base64.
You can convert binary to base64 using base64_encode.
Just do:
base64_encode($signature);
Read more here: http://php.net/manual/en/function.base64-encode.php
Related
I am working with GlobalSIgn digital signature using TCPDF. I send a hash of the PDF to GlobalSign and they return and hex encoded signature for the file.
TCPDF on the other hand signs documents using certificate file and private keys and they don't provide and option for using HEX encoded signatures while GlobalSign give hex signature without the private keys.
How can I add the HEX encoded signature into the PDF in PHP?
You could try using SetaPDF (PHP Library) in order to attach a hex signature from an external web service:
https://manuals.setasign.com/setapdf-signer-manual/signature-modules/individual-module/
I'm trying to implement the Google Safebrowsing update API v4 in PHP.
But I can't figure how to correctly decode the rawHashes.
(The rawHashes are 4-bytes-truncated sha256 hashes and then concatenated).
I am trying the native base64_decode of PHP but I can't fully decode the string, and I don't know what the next step is.
According to the API documentation here's how the rawhashes are encoded :
string (bytes format)
The hashes, in binary format, concatenated into one long string. Hashes are sorted in lexicographic order. For JSON API users, hashes are base64-encoded.
A base64-encoded string.
I an very simply decoding the string like so:
$decoded = base64_decode($rawHashes);
The base64 encoded string look like this:
"AAAIYAAAC90AABOxAAAjDgAALZIAAEbKAABIHwAA..."
And the base64 decoded string look like this:
b"\x00\x00\x08`\x00\x00\vÝ\x00\x00\x13±\x00\x00#\x0E\x00\x00-’\x00\x00FÊ\x00\x00H\x1F\x00\x00^\x06\x00\x00bF\x00\x00h²"
As you can see something is not right and I must have missed a step but I can't figure which one.
As Mjh said in the discussion nothing is wrong about base64_decode and nothing else is needed.
Nothing's wrong. You just aren't reading carefully. Here, read what it says: The hashes, in binary format. It says binary format. After decoding, you got binary representation of the data. Using bin2hex should return a human-readable hash. $hash = bin2hex(base64_decode($your_encoded_hash)); - Mjh
The decoded string was looking weird as it is binary data (Raw SHA256 hash) although it is totally correct. To get the hashes in a more convenient encoding it's possible to convert the binary represented data to hex represented data with the php function bin2hex
$hash = bin2hex(base64_decode($your_encoded_hash));
From what I know of base64_decode, it just works. Something must be wrong in your $rawHashes string. If you have line breaks in your string, you need to get rid of them by replacing them with an empty string. The hash that base64_decode needs should be one long line of base64 encoded string. It is not uncommon to receive a hash that is broken into multiple lines.
Try this ...
$decoded = base64_decode(str_replace(PHP_EOL, "", $rawHashes));
I have string that create by mssql that base64 of utf-16 string:
SABlAGwAbABvACAAVwBPAHIAbABkAA==
The decoded version is :
Hello WOrld
This is .NET tools that can use be for decode http://www5.rptea.com/base64/ (Use UTF-16)
How can i convert this using php mb or base64 ?
This is my convertion that return wrong characters:
var_dump(mb_convert_encoding(base64_decode('SABlAGwAbABvACAAVwBPAHIAbABkAA=='), "UTF-8", "UTF-16"));
// string(33) "䠀攀氀氀漀 圀伀爀氀搀"
"UTF-16" is big endian, but your text is encoded little endian. Use "UTF-16LE" instead.
I want to encode my urls in base64 and decode it in my functions and no body can decode it how can i do this.
<?php
$somestring = 'here is my some string';
$url = 'http://google.com/'.$somestring;
base64_encode($url);
?>
Base64 is not meant for encrypting sensible data. It's merely a means of representing data in another way. What it does, it takes binary data and converts it to ASCII, so that binary data can be represented with ASCII characters.
If you want to encrypt strings like your URLs, you have to choose an encryption algorithm like Blowfish, which is available in the PHP bcrypt extension.
I have an encrypted message from the openssl_private_encrypt methode. But I need it in 32 bit hex. How can I convert it? Can someone tell me witch format it the encrypted message has?
I would run the resulting string through base64_encode(): http://php.net/manual/en/function.base64-encode.php