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
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+5.9k Golang : Generate multiplication table from an integer example
+5.2k Golang : Issue HTTP commands to server and port example
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+5.3k Javascript : Change page title to get viewer attention
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+5k Golang : Calculate a pip value and distance to target profit example
+5.6k Golang : Shortening import identifier
+13.7k Golang : Check if an integer is negative or positive
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+13.4k Golang : Generate Code128 barcode
+21.1k Golang : For loop continue,break and range