Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Verify Java SignatureDemonstrates how to verify a digital signature produced by Java. Downloads: MS Windows Visual C/C++ Libraries Linux/CentOS C/C++ Libraries MAC OS X C/C++ Libraries Solaris C/C++ Libraries C++ Builder Libraries // Needs #include <CkPublicKey.h> // Needs #include <CkRsa.h> CkString strOut; CkPublicKey pubKey; bool success; // Load an RSA public key from an ASN.1 DER file success = pubKey.LoadRsaDerFile("pubKey.der"); if (success != true) { strOut.append(pubKey.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } const char * pkeyXml; // Get the public key in XML format: pkeyXml = pubKey.getXml(); CkRsa rsa; // Any string argument automatically begins the 30-day trial. success = rsa.UnlockComponent("30-day trial"); if (success != true) { strOut.append(rsa.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Import the public key into the RSA component: success = rsa.ImportPublicKey(pkeyXml); if (success != true) { strOut.append(rsa.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } rsa.put_EncodingMode("base64"); const char * strData; strData = "The quick brown fox jumps over the lazy dog"; // IMPORTANT: This Base64 signature will have to be updated // with the digital signature produced by the Java code at: // http://www.cknotes.com/?p=283 const char * base64Sig; base64Sig = "VGV5A+bodHBpBwwJZdf17Bv+lkBTm/gteOf8iCgEEfNzBosZLaAB8X55BIZIkE2zKRXoMcJT+iCxsj+1hnlwJeKZ+Gya58lrHw6NWm2N0O/KyfnuEzADOM86X0xrkgdFT6SYpbZ9dWPC59NiHeEdVyjOXNJ3fBpUSQ5/5pvVWm0="; // Verify the signature produced by the Java code at: // http://www.cknotes.com/?p=283 // The VerifyStringENC method hashes the input data and verifies // the hash against the signature. success = rsa.VerifyStringENC(strData,"sha-1",base64Sig); // Is the signature verified? if (success == true) { strOut.append("Signature Verified!"); strOut.append("\r\n"); } else { strOut.append("Signature not verified!"); strOut.append("\r\n"); } SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.