Skip to Content
0

Groovy script to decodebase64 and message digest SHA1. unable to run the script

Jan 25 at 01:44 PM

56

avatar image

Hello Experts,

I'm pretty new to Groovy scripts. I'm using script to perform decodebase64 on string and do Messagedigest SHA1 on the data. I had managed to get below code but its not working.

import java.security.*;

def Message processData(Message message)

{

//Body def body = message.getBody(String.class);

String decoded = body.bytes.decodeBase64().toVarchar();

MessageDigest sha1 = MessageDigest.getInstance("SHA1");

byte[] digest = sha1.digest(decode.getBytes());

digest = new BigInteger(1, digest).toString(16);

message.setBody(digest);

return message;

}

Input would be:

kIAUQJVfhfLaTF2G4WouvCmZqA2zhFhujfqe3g1I4WBJobFrBWcXKG5XoPM1MQZF9UeoM0o99tf8FHVEkEIkN1s0Pw7vXyHurkbiY/Dic56Fqa+PovU9gU4US+oLHoEMSpoDMtrVtAskS0h6bCgv1Hph/1QHTlVeto/GIw0Obb9CtSqlfhoXL8ZqCBMlsWClF8q31PZaD4vt8ZRzjm/fnA1YsH8Fo5PfxdWFEVrsprvDyUHuRvr0CHbDyE7qszgYA+Ri0ylnulPEqOlsBvNpiXoiEtoOnFOjZrWmLCM6IjnR8b2efnTRQsELdYr3FjRbg1kLDz3xUDGBwTplF31CSw==

After decoding the input has unicode characters in it. I'm unable to get to it. After SHA1 the output would be of 40 char.

I'm unable to achieve this with standard functions because output of standard decode function has Unicode characters.

Can you guys please help.

Regards,

Rajesh

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Rajesh Marupaka Jan 25 at 03:33 PM
0

Hi Guys,

I was able to get the script working. Below is the script

import java.security.*;

import java.security.MessageDigest;

def Message processData(Message message)

{

//Body

def body = message.getBody(String.class);

def digest = MessageDigest.getInstance('SHA1').digest(body.decodeBase64())

def result = new BigInteger(1, digest).toString(16) message.setBody(result);

return message;

}

Regards,

Rajesh

Share
10 |10000 characters needed characters left characters exceeded