DataPower

 View Only
Expand all | Collapse all

Passing Public Key as an Object to verify.verify() function

  • 1.  Passing Public Key as an Object to verify.verify() function

    Posted Tue October 08, 2024 06:52 AM

    Hi,

    I am facing an issue in passing the public key (secretKeyName) in the below verify function. Kindly help to pass the key as an object.

    secretKeyName : 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEmQpiWIeXaU8RtdtLsPYuyLEtgTeGV3zaLdW+6YYtoxz52Y1nf3/fNevibeF46nLS1eiEqNfjJSLG5xM8g1i9eA=='

    signedChallengeString : 'MEYCIQDKP/k1iXB8j3UTTvAcqOMhCKJMJ29x1s8MnJODwUpOlgIhAPFzn6kz05QH8FBRWMEfz3eUoYFufsadoTpRN7agHfBA'

    textToVerify = '["5ruvXSdVcgt4/vXBM1D3GcTfk+Fx6blroLauFYWnX75zYlx7XYXtMuy30d9Du/7aacgiggvXcDn1obJDoAHUH51lRqbzXg6X60PMwqsxQ7mwCahB6O2VKIOrDxt0am/jAq9Tzy8HMm5p/rflfVLT0LEWpOLqBxVpa0NqH5HTYtLT3LVEjkIwyPLlXo0JPzA2Zwq7VGdcRHTJTeYI+7V4rWbJwJXpVMAp3EMf9lF2nkdrusPhuF9xGibf+YVJyNdysc50/5XZyqRtxZ5MpMAEk3jpkw7w2Ufkh0x4o0Zzl9i4Fwut5fExAHbxs5DmfuMIErouqKeiPZF4wkqTSW0M6NGIzxuAX2q4pATJWUbDz/iPNlDccwySkg3Ohg+B5mmCFPwY8ecbaFBRaENr/S1TMm9RP50zxnRF7ZMiBUdk8dQkx3xPedrBdtz0fhgypHhSU3BfqJNJrMAzsicxhC3LZDGjIPYtgNf2Jc40Ml7E/HrzPVmKG0zIWf75YvIUqp1Qd/xXNRaloFyAoW8JWLh3/OfJhDxxKY4idu3VMQTiBmwzC11DkPDm9jw7WsKYWXmWVrm149+0bE1hs82izH0zQ4zgJPIC8imuDFbv7aD7et6fBDn88NM5oWalqjI+sftALjoYCyXAbIRXcWYoCvIH6TjqCBkPgv+pVpwjh8sjdqk=","s8HRVutaDapmd8WEhdSpdodefcMwcRfrhJ0mt5F39ZXPZZbZlfYF/0GY6+hLRemPfLVFHuGP4fKTujKAUgB6/TDRSi0Yfm6xztqE0ufI236g5nwUoIWvuYRO+Lu959EG204Ad/Imoeiqs0hKyUqodZmVpsLoK4Gt2vcSisy9MpxM9bqtYQcPqlOZLky/W187qlLxRxuPPUPFfflp5YlxnjwigfljX88qC6RJcjGiL1v2XaiWqrN/+9sdkup+UMJkecYc78B28d/i/+kas656p2849TLu7ttn078zz0EXRmQYvPDjxUPWxNdEmwVpCeeWrYppvaENRIjG0teWzFNQTfzIEEZboXiY1CQy+odkPNunaXpy+gdVBdI1VVv8j/d6zx1FAzTZEMfYec04O3Y6HSAzWN9L/OSpUQ3do8jLYPe2o5wwmdD8/5hm8/Ylvg/wLPbXr2jawIGTUV2HKsGmywv0+m2BV0zSjFbB9IT8DKF7U63Rd3Tebg1k50/Qse5a8wRGIeeFUt4KFWZEvY+LqhTmHgmo7DJRem55sKnP27itX69ELDkOzhHkUkhowb5pB7f1c77Fu8ycJKA+XFd3bR3zbg7fL3tmh75GXNvmY4hlTiAVGfAj8Dz/tllWbKk+VR4mq9Me5YHt4S0MvYouF6Gh+kWvV7IyGNrq1hu7sNg=","9YIw26gmJdei58QNVaTkI9iI6Ufl54796zidkKFq15sz5UCXXijM7r9+","xyz123","1707399602000"]'

    Verify Function:

    exports.verifySignedString = function (textToVerify, signedChallengeString, secretKeyName) {

        var verify = crypto.createVerify('ecdsa-sha256');

        verify.update(textToVerify).verify(secretKeyName, signedChallengeString, function (error) {
            if (error) {
                console.error("verification fail : " + error);
                session.output.write(false);
            } else {
                console.error("verification result : success ");
                session.output.write(true);
            }
        });
    }

    i have tried to pass like below, but it still throws error. Kindly let me know how to pass it as an object as mentioned in the IBM crypto module page https://www.ibm.com/docs/en/datapower-gateway/10.6.x?topic=gatewayscript-key-object-usage

    var publickey = '-----BEGIN PUBLIC KEY-----' + 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEmQpiWIeXaU8RtdtLsPYuyLEtgTeGV3zaLdW+6YYtoxz52Y1nf3/fNevibeF46nLS1eiEqNfjJSLG5xM8g1i9eA==' + '-----END PUBLIC KEY-----';



    ------------------------------
    Divya Kandasamy
    ------------------------------


  • 2.  RE: Passing Public Key as an Object to verify.verify() function

    Posted 2 days ago

    Hi @Divya Kandasamy,
    You can implement the key as an object by adding it to DataPower and referencing it through a variable.
    like this example :   https://www.ibm.com/docs/en/datapower-gateway/10.0.1?topic=apis-crypto-module#sign.sign



    ------------------------------
    Gibin G Luke
    ------------------------------