Created
March 28, 2018 08:54
-
-
Save josemmo/4c628fde8e8a5882274c811cda0d5c5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean sign(PrivateKey pk) { | |
// Comprobar que no está firmada la transacción | |
if (signature != null) return false; | |
// Comprobar que la clave privada se corresponde con esta transacción | |
PublicKey expected = getPublicFromPrivate(pk); | |
if (!expected.equals(from)) return false; | |
// Intentar firmar la transacción | |
try { | |
Signature sig = Signature.getInstance("SHA1WithRSA"); | |
// Especificar clave privada | |
sig.initSign(pk); | |
// Especificar String a firmar | |
sig.update(from + to + amount + ";" + timestamp); | |
// Guardar los bytes de la firma | |
signature = sig.sign(); | |
return true; | |
} catch (Exception e) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment