Skip to content

Instantly share code, notes, and snippets.

@cvakiitho
Created June 10, 2021 12:25
Show Gist options
  • Save cvakiitho/b4218e90b4306102bef8d1ef6c52e575 to your computer and use it in GitHub Desktop.
Save cvakiitho/b4218e90b4306102bef8d1ef6c52e575 to your computer and use it in GitHub Desktop.
Script to get hash from groovy script for script-approval
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
class Scratch {
public static void main(String[] args) {
String language = "groovy";
String script ='''
'''
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.update(language.getBytes("UTF-8"));
digest.update((byte) ':');
digest.update(script.getBytes("UTF-8"));
print(this.toHexString(digest.digest()))
}
public static String toHexString(byte[] data, int start, int len) {
StringBuilder buf = new StringBuilder();
for( int i=0; i<len; i++ ) {
int b = data[start+i]&0xFF;
if(b<16) buf.append('0');
buf.append(Integer.toHexString(b));
}
return buf.toString();
}
public static String toHexString(byte[] bytes) {
return toHexString(bytes,0,bytes.length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment