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
+32.5k Golang : Copy directory - including sub-directories and files
+52.6k Golang : How to get struct field and value by name
+6.9k Golang : Calculate BMI and risk category
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+48.5k Golang : Upload file from web browser to server
+23.1k Golang : simulate tail -f or read last line from log file example
+13.7k Golang : Activate web camera and broadcast out base64 encoded images
+8.3k Golang : Auto-generate reply email with text/template package
+7.5k Gogland : Single File versus Go Application Run Configurations
+6.7k Golang : Humanize and Titleize functions