Skip to content

Instantly share code, notes, and snippets.

@mkaraoz
Created March 15, 2021 23:04
Show Gist options
  • Save mkaraoz/a092c2e238c515fdf434d2a5069b8c53 to your computer and use it in GitHub Desktop.
Save mkaraoz/a092c2e238c515fdf434d2a5069b8c53 to your computer and use it in GitHub Desktop.
/**
* Supported signature algorithms:
* https://developer.android.com/reference/java/security/Signature
*/
public byte[] sign(String message) throws Exception {
KeyPair keyPair = getKeys();
Signature signature = Signature.getInstance("SHA256widthECDSA");
signature.initSign(keyPair.getPrivate());
signature.update(message.getBytes());
byte[] signedData = signature.sign();
Log.d("_MK", Base64.encodeToString(signedData, Base64.DEFAULT));
return signedData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment