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
+17k Golang : Capture stdout of a child process and act according to the result
+9.8k Golang : Qt get screen resolution and display on center example
+9.4k Android Studio : Indicate progression with ProgressBar example
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+8.9k Golang : Gaussian blur on image and camera video feed examples
+15.9k Golang : Get file permission
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+7k Web : How to see your website from different countries?
+20.7k Golang : Saving private and public key to files
+5.9k Golang : Denco multiplexer example
+6.1k Golang : Scan forex opportunities by Bollinger bands