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
+5.1k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+19.2k Golang : Populate dropdown with html/template example
+9.7k Random number generation with crypto/rand in Go
+9.3k Golang : Temperatures conversion example
+8k Golang : Get all countries phone codes
+23.1k Golang : simulate tail -f or read last line from log file example
+12.1k Golang : Pagination with go-paginator configuration example
+5.2k JavaScript/JQuery : Redirect page examples
+6k Golang : Compound interest over time example
+46.4k Golang : Encode image to base64 example
+9.7k Golang : Populate slice with sequential integers example
+8.8k Golang : HTTP Routing with Goji example