Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Jython Crypto Coding for hmacSHA256

Options
ctyler_1
ctyler_1 Posts: 9
edited May 2022 in SOAtest

Can anyone help me get the right imports to attempt the below using Jython in SOAtest?

Execute Anonymous: String digestTime = string.valueOf(system.currentTimeMillis());//This is standard
Execute Anonymous: String digest = EncodingUtil.base64Encode(Crypto.generateMac('hmacSHA256', Blob.valueOf(digestTime), Blob.valueOf(Utils.getGlobalSetting('AppDigest'))));
Execute Anonymous: System.debug('***** digestTime:'+digestTime);
Execute Anonymous: System.debug('***** digest:'+digest);

Tagged:

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,235 ✭✭✭
    Options

    I am not familiar with what java libraries you are attempting to use. You reference classes like EncodingUtil, Crypto, and Utils but none of those seem like java classes that are provided by either the Java runtime or SOAtest.

    One thing I will say is that to base64 encode a byte array you should be using java.util.Base64 class from the Java runtime. From Jython, your import would be "from java.util import Base64". To encode a byte[] as base64, you would write something like "Base64.getEncoder().encode(bytesToEncode)"

  • ctyler_1
    ctyler_1 Posts: 9
    Options

    @benken_parasoft Thanks and yes I have some base 64 scripts working which is a little diff format than the above. I looked at https://docs.python.org/3/library/hmac.html but never really could figure the import needed. Trying to find some jars to import or put into SOAtest was a no go as well.

  • benken_parasoft
    benken_parasoft Posts: 1,235 ✭✭✭
    Options

    I looked at https://docs.python.org/3/library/hmac.html but never really could figure the import needed.

    This "hmac" module is part of the Python Standard Library. The top of your script would just have "import hmac". However, you may need to use SOAtest 2022.1 for this to work. Earlier versions failed to load some modules from the Python Standard Library.

Tagged