Integration

Get Involved. Join the Conversation.

Topic

    logu Prasanth
    How to calculate signature in OIC using HMAC sha 256Answered
    Topic posted February 12, 2019 by logu PrasanthSilver Medal: 2,000+ Points, tagged Adapters, API, E-Business Suite, Integration, Mapping, Orchestration, PaaS, REST, SOAP, Web Services, xml 
    420 Views, 19 Comments
    Title:
    How to calculate signature in OIC using HMAC sha 256
    Summary:
    Calculate signature in OIC using HMAC sha 256
    Content:

    Hi All,

    In OIC, How to calculate signature using HMAC sha256

    Is there any script available in OIC calculate HMAC sha256 ??

     

    Regards,

    Logu,

     

    Best Comment

    Dheeraj

    Add above library and craete a function as below. These are cryptoJs library and needs to be used as below.

    var message = "Message";
    function Hmac(key){
      var hash = CryptoJS.HmacSHA256(message,key);
      var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
      return hashInBase64;
    }
    
    Let me know if this works. I tried this recently and gives me result.
    

    Comment

     

    • Show/Hide RepliesAnonymousposted March 19, 2019
      This has been deleted by the author
      • logu Prasanth

        Hi John,

        When i tried this code getting below error while activating the Integration.

         

        Deployment Failed: Error occurred during deployment of component: TWO_FACTOR_AUTH to service engine: implementation.bpel, for composite: TWO_FACTOR_AUTH: ORABPEL-05215 Error while loading process. The process domain is encountering the following errors while loading the process "TWO_FACTOR_AUTH" (composite "oracleinternalics/TWO_FACTOR_AUTH!01.00.0000*3e9ee41e-1494-4ec8-80ef-dd9219521999"): Error while creating process. error while attempting to instantiate the class for the process "oracleinternalics/TWO_FACTOR_AUTH!01.00.0000*3e9ee41e-1494-4ec8-80ef-dd9219521999" (revision "TWO_FACTOR_AUTH"); the exception reported was: ReferenceError: "require" is not defined. (js/HMAC_SHA256_01.00.0000/Hmac-sha256.js#1) This error contained an exception thrown by the underlying process loader module. Verify the exception trace in the log (with logging level set to debug mode). . This error contained an exception thrown by the underlying process loader module. Check the exception trace in the log (with logging level set to debug mode). If there is a patch installed on the server, verify that the bpelcClasspath domain property includes the patch classes.

    • logu Prasanth

      Thank you so much John.

      reference library we should add right?

      1. enc-base64.min.js

      2.hmac-sha256.min.js

      3.crypto-js.min.js

       

       

      • John Graves

        Right.  You'll need to add the modules in the node_modules directory and zip it up for the library.  I typically do my testing using nodejs and build out the needed modules, then zip and upload.   That's why I have the code at the end that calls the method and displays the results.

        • logu Prasanth

          Hi John,

          When i tried this code getting below error while activating the Integration.

           

          Deployment Failed: Error occurred during deployment of component: TWO_FACTOR_AUTH to service engine: implementation.bpel, for composite: TWO_FACTOR_AUTH: ORABPEL-05215 Error while loading process. The process domain is encountering the following errors while loading the process "TWO_FACTOR_AUTH" (composite "oracleinternalics/TWO_FACTOR_AUTH!01.00.0000*3e9ee41e-1494-4ec8-80ef-dd9219521999"): Error while creating process. error while attempting to instantiate the class for the process "oracleinternalics/TWO_FACTOR_AUTH!01.00.0000*3e9ee41e-1494-4ec8-80ef-dd9219521999" (revision "TWO_FACTOR_AUTH"); the exception reported was: ReferenceError: "require" is not defined. (js/HMAC_SHA256_01.00.0000/Hmac-sha256.js#1) This error contained an exception thrown by the underlying process loader module. Verify the exception trace in the log (with logging level set to debug mode). . This error contained an exception thrown by the underlying process loader module. Check the exception trace in the log (with logging level set to debug mode). If there is a patch installed on the server, verify that the bpelcClasspath domain property includes the patch classes.

        • logu Prasanth

          What you mean by node_moduledirectory??

          • John Graves

            Sorry I haven't been able to get back to this for awhile.  You are right.  The 'require' command is not allowed in the library.  Let me try to build out something else.  I might be able to use browserify to bring in the crypto command into a standalone js file.  I'll let you know how I go.

      • Dheeraj

        Add above library and craete a function as below. These are cryptoJs library and needs to be used as below.

        var message = "Message";
        function Hmac(key){
          var hash = CryptoJS.HmacSHA256(message,key);
          var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
          return hashInBase64;
        }
        
        Let me know if this works. I tried this recently and gives me result.
        
        • logu Prasanth

          I have done with my own another code refered with the above libraries. 

          function createHmac(payload,key) {
          var x = CryptoJS.HmacSHA256(payload,key).toString(CryptoJS.enc.Hex);
          return x;
          }
          • Khristofer Aram Salvanera

            Hi Logu,

            How did you add the following in the reference library? 

            1. enc-base64.min.js

            2.hmac-sha256.min.js

            3.crypto-js.min.js

            I'm getting the error "Failed to register library, Library file enc-base64.min.js should contain at least one JS file with valid functions." when I try to register the JS. Same error for the other two JS.

            I downloaded the copies of the JS above from https://www.cdnpkg.com/crypto-js.

            Hopefully you can help me with my issue.

            Thanks,

            Aram

             

            • logu Prasanth

              Here I attached, what file I am using right now. kindly test with these files.

              Let  me know if any concern

              Js.zip (17KB)
              • Khristofer Aram Salvanera

                Thank you for your reply Logu.  I tried to register one of the JS file you have used, and it is giving me the same error I have before.

                 

                • Hemanth Lakkaraju

                  This should help start how to build js libraries and use them - Using Libraries & Adding Callouts

                  If you are using the zip file attached by logu, you can use the js files in it, jar them and upload that as a library, instead of individual files and that should solve your problem.

                  • Khristofer Aram Salvanera

                    Hi Hemanth,

                    Thank you for your comment. As I'm new in JS and Java, may I ask what tool I can use to compress the js files and convert it into jar file?

                    • Hemanth Lakkaraju

                      I generally use java command line to generate the jar file like below:

                      jar -cvf Sample.jar *.js

                      Picks up all js files in current location and create a jar with name Sample in current location, assuming JAVAHOME and $JAVAHOME/bin are set in PATH variable.

                      • Khristofer Aram Salvanera

                        Thank you. I have done what you have instructed and produced a jar file, however, I got the same error when I tried to register the jar file.  I have attached the jar file that I have created.

                         

                        Cyrpto.zip (17KB)
                        • logu Prasanth

                          I tried jar on my side what u have attached. successfully got registered with a warning message 

                           

                          • Khristofer Aram Salvanera

                            Thank you for all the help! Finally, I was able to upload successfully in the Library. I have updated my function and created a new jar file. I have attached the working jar file I have created. 

                            • Dheeraj

                              Change the name of reference library functions  from *.min.js to *-min.js. This will get rid of warnings and also will only show your custom HMAC generator javascript while configuring the function in library.