Last active
September 26, 2023 14:01
-
-
Save Grrrben/96f833648bd8371408dfa3f6641bb7da to your computer and use it in GitHub Desktop.
Signing and Verifying using Golang RSA
This file contains hidden or 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
// Sign returns a signature made by combining the message and the signers private key | |
// With the r.Verify function, the signature can be checked. | |
func (r *RsaIdentity) Sign(msg []byte) (signature []byte, err error) { | |
hs := r.getHashSum(msg) | |
signature, err := rsa.SignPKCS1v15(rand.Reader, r.private, crypto.SHA256, hs) | |
return | |
} |
This file contains hidden or 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
// Verify checks if a message is signed by a given Public Key | |
func (r *RsaIdentity) Verify(msg []byte, sig []byte, pk *rsa.PublicKey) error { | |
hs := r.getHashSum(msg) | |
return rsa.VerifyPKCS1v15(pk, crypto.SHA256, hs, sig) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment