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
+16.1k Golang : How to check if input from os.Args is integer?
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+11.3k Golang : Post data with url.Values{}
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+5.6k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+8.7k Golang : Find duplicate files with filepath.Walk
+13k Golang : Calculate elapsed years or months since a date
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+5k Python : Convert(cast) bytes to string example
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+8.5k Golang : How to check if input string is a word?