Good day. I was busy connecting to a cyber payment, everything would be fine but it’s impossible for me to check the signature of the string that they send.
Input data:
The string to which we have the signature
String text = "action=check&number=00842&amount=10.54&type=1"
Signature
String sign = "C41545C19E86D0001F11D9D98EA6630EFAE4AB26AEC5933E05B5ADE7B6571B7B0FF5230F33B306D174290D3E6FAF1133A6FD1F0155A5D04294DE7DD0A20E3B037884121D399CEF9D91EC519AB56B67448E116EAF8629293E1F66A780E0028A2EC7C831D1F5ADF68B9703B576B30D80DA940187A23104A9304A74A9C86AD6E68B";`
Public key http://yadi.sk/d/u892DkgA3zh9a
So I load the public key
PEMReader reader = new PEMReader(new FileReader(f)); Object obj; PublicKey pubKey = null; while ((obj = reader.readObject()) != null) { if (obj instanceof PublicKey) { pubKey = (PublicKey) obj; } }
If after that I make Sytem.out.println(pubKey)
, I get a module and a public exponent at the output. RSA key algorithm, X.509 format.
So I do the signature verification:
try { byte [] data = text.getBytes(); byte [] subscript = subscriptText.getBytes(); Signature signature = Signature.getInstance("RSA","BC"); signature.initVerify(pubKey); signature.update(data); System.out.println(signature.verify(subscript) ? "Подписано верно!!!!!!!!!!!!!!!!!!": "Подписано не верно"); } catch (Exception e) { e.printStackTrace(); }
But the result is always the same. He made his signature on this line (with his private key) and tried to verify the signature with his public key, but he also received a negative answer. Errors do not deduce what, just says not the correct signature.
Help verify the signature.
**Update** техподдержка киберплата скинула код на perl в котором проверка проходит успешно. осталось только реализовать все на Java #!/usr/bin/perl use strict; use Crypt::OpenSSL::RSA; my $cyberplat_message='action=check&number=00842&amount=10.54&type=1&sign=C41545C19E86D0001F11D9D98EA6630EFAE4AB26AEC5933E05B5ADE7B6571B7B0FF5230F33B306D174290D3E6FAF1133A6FD1F0155A5D04294DE7DD0A20E3B037884121D399CEF9D91EC519AB56B67448E116EAF8629293E1F66A780E0028A2EC7C831D1F5ADF68B9703B576B30D80DA940187A23104A9304A74A9C86AD6E68B'; my $message=$cyberplat_message; my $signature_hex=$cyberplat_message; undef $cyberplat_message; $message=~s/\&sign.*?$//; $signature_hex=~s/^.*?\&sign\=(.*?)$/$1/sg; my $signature_bin=pack("H*",$signature_hex); my $pub_key_string=`cat CyberPlat_RU_pub.pem`; my $rsa_pub = Crypt::OpenSSL::RSA->new_public_key($pub_key_string); if (!$rsa_pub->verify($message, $signature_bin)) { print "Error"; } else { print "Succes"; }
& number =**Update** техподдержка киберплата скинула код на perl в котором проверка проходит успешно. осталось только реализовать все на Java #!/usr/bin/perl use strict; use Crypt::OpenSSL::RSA; my $cyberplat_message='action=check&number=00842&amount=10.54&type=1&sign=C41545C19E86D0001F11D9D98EA6630EFAE4AB26AEC5933E05B5ADE7B6571B7B0FF5230F33B306D174290D3E6FAF1133A6FD1F0155A5D04294DE7DD0A20E3B037884121D399CEF9D91EC519AB56B67448E116EAF8629293E1F66A780E0028A2EC7C831D1F5ADF68B9703B576B30D80DA940187A23104A9304A74A9C86AD6E68B'; my $message=$cyberplat_message; my $signature_hex=$cyberplat_message; undef $cyberplat_message; $message=~s/\&sign.*?$//; $signature_hex=~s/^.*?\&sign\=(.*?)$/$1/sg; my $signature_bin=pack("H*",$signature_hex); my $pub_key_string=`cat CyberPlat_RU_pub.pem`; my $rsa_pub = Crypt::OpenSSL::RSA->new_public_key($pub_key_string); if (!$rsa_pub->verify($message, $signature_bin)) { print "Error"; } else { print "Succes"; }