LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Java node SHA1 encryption

    Employee
    Posted 05-31-2012 20:15

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Adam Williamson

    Hello,

    I am interested in encrypting data in a field to output the original field and the SHA1 encryption.
    I have obtained the below Java code but I am not familiar enough with the Java node to be able to implement it.

    Can anyone assist?

    import java.io.UnsupportedEncodingException; 
    import java.security.MessageDigest; 
    import java.security.NoSuchAlgorithmException; 
    
    
    public class SHA1_Encryption {
    
        public static String convertToHex(byte[] data) { 
            StringBuffer buf = new StringBuffer();
            for (int i = 0; i < data.length; i++) { 
                int halfbyte = (data[i] >>> 4) & 0x0F;
                int two_halfs = 0;
                do { 
                    if ((0 <= halfbyte) && (halfbyte <= 9)) 
                        buf.append((char) ('0' + halfbyte));
                    else 
                        buf.append((char) ('a' + (halfbyte - 10)));
                    halfbyte = data[i] & 0x0F;
                } while(two_halfs++ < 1);
            } 
            return buf.toString();
        } 
     
        public static String SHA1(String text) 
        throws NoSuchAlgorithmException, UnsupportedEncodingException  { 
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
        } 
    
    }


  • 2.  RE: Java node SHA1 encryption

    Employee
    Posted 06-01-2012 03:42

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    It's pretty much a matter of:
    1. Setting a parameter on the node which will tell you which field to encrypt
    2. Then, in the setup method
      1. Reading this parameter into the java node
      2. Ensuring that the referenced field exists in the input metadata
      3. Setting up the output metadata
    3. Then, in processAll
      1. Reading each record
      2. Extracting the field value from this record
      3. Using your provided method to obtain a SHA1 encrupted version of the field
      4. Writing this to an output record

    All of these topics (except for step 3.3 which is specific to this case, but pretty trivial) are covered in the Java Node Getting Started Guide, so you should be able to figure it out from there, using the examples in the getting started guide as a basis.

    In any case, I've attached a node which I think does what you probably want.
    Attachments:
    sha1.brg


  • 3.  RE: Java node SHA1 encryption

    Employee
    Posted 06-03-2012 16:55

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Adam Williamson

    Thank you Tim, the attached works perfectly. I will refer to the Java Node Getting Started Guide to get my head around future implementations of Java logic. I did get the SHA1 logic working in a python filter node but I think the Java node will provide faster processing.