Skip to Content

UDF to create SHA512 Hash of String

Hi experts, I hope you can help.

We have a requirement where some strings need hashed (i.e. password and signature key).
I have read previous blog, but struggling to get it working:
Vadim Klimov
Former Member did you use both UDFS or a combo of the 2 to achieve your result?

This mapping requirement is relatively simple - UDF to SHA512 Hash a string returning the hashed result in capital format. Basically the same as:
Input string: TestHash
SHA512 Hash of your string:6D9DB987D524AFB3EA05F4679E7A4A16C242C45BE6E40891FF13D4AE24B846917994AD54731F3AF0DE96921C98D242397DC0CA0EAEC53BDDA87053F3573E286C

Many thanks in advance

David King

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Feb 27 at 02:44 PM

    Hi David ,

    Please find below UDF to create SHA512 Hash of String

    After HASH String you can simply use the toUpperCase functionality from mapping

    public String SHA512(String s, Container container) throws StreamTransformationException{
      try {
    getTrace().addInfo(s); md ="SHA-512"); 
      byte[] byteData=md.digest();
      s=new String(byteData);
      //converting to hex
      StringBuffer hexString = new StringBuffer();
          for (int i=0;i<byteData.length;i++) {
          String hex=Integer.toHexString(0xff & byteData[i]);
            if(hex.length()==1) hexString.append('0');
      } catch (Exception e) {
      // TODO Auto-generated catch block
      throw new StreamTransformationException(e.getMessage());
      return s;
    Add comment
    10|10000 characters needed characters exceeded