-1

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

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 have tried , but I did not get any results. I get an sign error as a result of the request.

$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);
3
  • 2
    If you get an error, you need to tell us exactly what it says, and which code line caused it. Please edit your question. Commented Jul 16, 2023 at 8:02
  • In the PHP code, sign $baseString and not $originalData. If the keys are identical (PrivateKey.xml in XML format and PrivateKey.pem in PEM encoding) both codes generate the same signature. If not, check if the keys are really identical. Commented Jul 16, 2023 at 8:19
  • Key.SignData, What is Key here? Commented Jul 16, 2023 at 8:52

1 Answer 1

0

My guess is wrong encoding of dataString / $baseString

The default string encoding in C# is UTF-16, in php however the encoding of a string is automatically ASCII, yet if not supported char appear in the string the encoding changed automatically to UTF-8 - so it depends what string the $baseString contain, you can check with mb_detect_encoding method if the encoding is still ASCII as expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.