Skip to content

Instantly share code, notes, and snippets.

@biafra23
Last active May 16, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biafra23/893eefa0eff9c163bfe5c7a29bde2896 to your computer and use it in GitHub Desktop.
Save biafra23/893eefa0eff9c163bfe5c7a29bde2896 to your computer and use it in GitHub Desktop.
private byte[] getDigestExtra(String toBeSigned, byte[] extra) throws NoSuchProviderException {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA1", "BC");
for (byte b : toBeSigned.getBytes()) {
System.out.println("b: " + Hex.toHexString(new byte[]{b}));
md.update(b);
}
for (byte b : extra) {
System.out.println("b: " + Hex.toHexString(new byte[]{b}));
md.update(b);
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return md.digest();
}
private byte[] getDigest(String toBeSigned, byte[] extra) throws PGPException, IOException {
JcaPGPDigestCalculatorProviderBuilder digestCalculatorProviderBuilder = new JcaPGPDigestCalculatorProviderBuilder();
PGPDigestCalculator digestCalculator = digestCalculatorProviderBuilder.build().get(HashAlgorithmTags.SHA1);
OutputStream os = digestCalculator.getOutputStream();
for (byte b : toBeSigned.getBytes()) {
os.write(b);
}
for (byte b : extra) {
os.write(b);
}
return digestCalculator.getDigest();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment