Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

khovsepyan's avatar

C# GetBytes() method PEM/SHA1 signature realization in PHP

I'm trying use this code for generation pem signature but i cant find similar methods in php (LARAVEL) to realization this. I have tried all similar methods in PHP but the results do not meet the requirements.

var bytes = Encoding.UTF8.GetBytes("/articles")
    .Concat(new byte[] { 0x00 })
    .Concat(Encoding.UTF8.GetBytes("get"))
    .Concat(new byte[] { 0x00 })
    .Concat(Encoding.UTF8.GetBytes("Accept-Language en-en Authorization Agent 0505"))
    .Concat(new byte[] { 0x00 });
    File.WriteAllBytes("digest.txt", bytes.ToArray());
    openssl dgst -sha1 -sign private.pem digest.txt > signature.txt
            var signatureInBytes = File.ReadAllBytes("signature.txt");
            var signatureInBase64 = Convert.ToBase64String(signatureInBytes);

Are there any suggestions?

0 likes
0 replies

Please or to participate in this conversation.