如何在PHP中使用私钥生成符号

时间:2019-04-13 03:10:37

标签: php openssl

我有私钥文件,我需要用私钥签名一些字符串。 我在这里显示了一些密钥(不是全部显示了一些密钥),谁能告诉我们如何生成

$data="Some Data";
$pkeyid = '-----BEGIN RSA PRIVATE KEY----- Lk43iPsiA1a3l3lwwLNy 8vTG1Xg0or08X5Uh+Bfj2/FhD8Wd4CfSWM4pD8h2u55mQkEo6CNo34uUaBK7b0mM MngpSl1e40XbSGb01d6YR3BBog0ZSYT7Fs2gLUinx2A0ta95sq5jUOnDOWvCerYv oIjy955oT0XfKLbPVcCHwiEmM3jRtKTT/sA/FI1VD9THE4I/lt3sQh/bOkAjNZTH 7nM5E3VvFMpacu91IFcEQaxx27EtZ4x6YZmApb4RFE4w0T0OzZeHoyOsH6+tFUiF WWjGkKECgYEA+GuuG/RidDkiwFR2Mvi5Q61Tw4kJePEcKsv0e40eQ1LduVAWp8F2 hce4wVAei -----END RSA PRIVATE KEY-----';

openssl_sign($data, $signature, $pkeyid); 
echo $signature;

我正在得到这样的输出

Output:

B��<�k����ozɌł+��   ��N�@�g}�&I�    vL,f�~�[�!1(�m}��3�� �Pb���|�-jh�Ņt�X���dN�Y#k�}u�- ��}}���U�*XV^��8��$�XN,A�������-�n�I ����Y|����Kwv�6��0��#�IZ]�vPZ"�6n�U�=��6����5�I�x�[S��ؚ{|��WE.��\�}�:Ϣ60�O�T�_QbJf���yh�.���l�L

我期望这样的输出,

C95E4D53EC92E311AE5BFABCB7E46928637AD0254A1D3C2E48D9B070B490AE7A79
85FE24D80A4544FFEDBFA29C36574B9667FC3F57DFBF5E1C4730C2DA3505B9F694399EDB5
58E39343FD9ED7A57F265EF5A3A8C6078471D7DAED52B4D8307206ED84B6AE35DC0000A7
116F9081B112A359B36FE2ECFA8604B5EDE5F305F717665A7C89BDAEEECAF67ADA97B583C
2314F5F6259B28C61AA8B7DBB74C9925B0ADEC3703288A907B632F133D7CFC35DC6A02003
7A4EA7F94CA5836C3FBFFC6DB050B0B879D1320C915754DFD565CBFFC4BBF18C1FD84530B
F4FED0B7D4AE1280666C060AFCD6D6CEF3ADFB3AC31CF4851700B28197D19174F5147B459
7E01A41BE

1 个答案:

答案 0 :(得分:0)

尝试对这些输出进行编码

<?php

$data = "Some Data";

$pkeyid = '-----BEGIN RSA PRIVATE KEY----- Lk43iPsiA1a3l3lwwLNy 8vTG1Xg0or08X5Uh+Bfj2/FhD8Wd4CfSWM4pD8h2u55mQkEo6CNo34uUaBK7b0mM MngpSl1e40XbSGb01d6YR3BBog0ZSYT7Fs2gLUinx2A0ta95sq5jUOnDOWvCerYv oIjy955oT0XfKLbPVcCHwiEmM3jRtKTT/sA/FI1VD9THE4I/lt3sQh/bOkAjNZTH 7nM5E3VvFMpacu91IFcEQaxx27EtZ4x6YZmApb4RFE4w0T0OzZeHoyOsH6+tFUiF WWjGkKECgYEA+GuuG/RidDkiwFR2Mvi5Q61Tw4kJePEcKsv0e40eQ1LduVAWp8F2 hce4wVAei -----END RSA PRIVATE KEY-----';

openssl_sign($data, $signature, $pkeyid);
echo bin2hex($signature);