I want to implement this code for bank payment in PHP. Can anyone help me? Thanks.
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.
$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);
我猜测数据字符串/基本字符串的编码错误。
在C#中,默认的字符串编码是UTF-16,在php中,字符串的编码自动为ASCII,但是如果字符串中出现不支持的字符,则编码会自动更改为UTF-8 - 所以这取决于$baseString包含的字符串,您可以使用mb_detect_encoding方法检查编码是否仍然是预期的ASCII编码。