Golang crypto/dsa.Sign() function example
package crypto/dsa
Sign signs an arbitrary length hash (which should be the result of hashing a larger message) using the given private key input and returns the signature as a pair of integers. The security of the private key depends on the entropy of rand. Note that FIPS 186-3 section 4.6 specifies that the hash should be truncated to the byte-length of the subgroup. This function does not perform that truncation itself.
Golang crypto/dsa.Sign() function usage example
// Sign
var h hash.Hash
h = md5.New()
r := big.NewInt(0)
s := big.NewInt(0)
io.WriteString(h, "This is the message to be signed and verified!")
signhash := h.Sum(nil)
r, s, err := dsa.Sign(rand.Reader, privatekey, signhash)
if err != nil {
fmt.Println(err)
}
signature := r.Bytes()
signature = append(signature, s.Bytes()...)
fmt.Printf("Signature : %x\n", signature)
See How to use DSA functions tutorial for more details
Reference :
Advertisement
Something interesting
Tutorials
+13.8k Golang : Gin framework accept query string by post request example
+22.2k Golang : Convert seconds to minutes and remainder seconds
+13.6k Golang : reCAPTCHA example
+16.6k Golang : Delete files by extension
+13.6k Android Studio : Password input and reveal password example
+6.6k Golang : Totalize or add-up an array or slice example
+17.6k Golang : delete and modify XML file content
+9.7k PHP : Get coordinates latitude/longitude from string
+8.2k Golang : Add build version and other information in executables
+10.2k Golang : How to profile or log time spend on execution?
+34k Golang : Proper way to set function argument default value
+7.3k Golang : How to fix html/template : "somefile" is undefined error?