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
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+7.5k Golang : Rot13 and Rot5 algorithms example
+7.9k Swift : Convert (cast) String to Float
+10.6k Golang : Bubble sort example
+14.6k Golang : How to get URL port?
+29.9k Golang : How to get HTTP request header information?
+6.8k Get Facebook friends working in same company
+7.5k Golang : Gorrila set route name and get the current route name
+6.3k Golang : Test input string for unicode example
+8.7k Golang : How to join strings?
+4.8k Facebook : How to place save to Facebook button on your website
+17.3k Golang : How to tell if a file is compressed either gzip or zip ?