[code=php]
<?php
function foo() {
$s = hash_hmac('sha256', 'Message', 'secret', true);
echo base64_encode($s);
}
?>
[/code]
[code=golang]
import (
b64 "encoding/base64"
"crypto/hmac"
"crypto/sha256"
)
//genHMAC256 generates a hash signature of the encrypted text
func genHMAC256(ciphertext, key []byte) []byte {
mac := hmac.New(sha256.New, key)
mac.Write([]byte(ciphertext))
hmac := mac.Sum(nil)
return hmac
}
...
//call the function
hmac := genHMAC256([]byte('Message'), []byte('secret'))
stringHmac := b64.StdEncoding.EncodeToString(hmac)
...
[/code]
|