search

Home  >  Q&A  >  body text

In PHP language, the C# ASCII code equivalent is expressed as

I want to implement this code for bank payment in PHP. Can anyone help me? Thanks.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

ASCIIEncoding ByteConverter = new ASCIIEncoding();

 

string dataString = "Data to Sign";

byte[] originalData = ByteConverter.GetBytes(dataString);

 

byte[] signedData;

 

RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider();

 

String PrivateKey= File.ReadAllText(Application.StartupPath + "PrivateKey.xml");

 

RSAalg.FromXmlString(PrivateKey);

 

signedData = Key.SignData(originalData,SHA1.Create());

 

String base64String = Convert.ToBase64String(signedData, 0, signedData.Length);

I've tried this but didn't get any results. Due to a problem with the request, I got a symbol error.

1

2

3

4

5

6

7

8

9

$baseString "Data to Sign";

$signedData = null;

$privateKey file_get_contents(config_path("PrivateKey.pem"));

$privateKeyResource = openssl_pkey_get_private($privateKey);

 

$signature = null;

 

if (openssl_sign($baseString$signedData$privateKeyResource, OPENSSL_ALGO_SHA1))

            $signature base64_encode($signedData);


P粉680087550P粉680087550598 days ago661

reply all(1)I'll reply

  • P粉674876385

    P粉6748763852023-07-18 14:03:48


    我猜测数据字符串/基本字符串的编码错误。

    在C#中,默认的字符串编码是UTF-16,在php中,字符串的编码自动为ASCII,但是如果字符串中出现不支持的字符,则编码会自动更改为UTF-8 - 所以这取决于$baseString包含的字符串,您可以使用mb_detect_encoding方法检查编码是否仍然是预期的ASCII编码。


    reply
    0
  • Cancelreply