Go lang generate hmac

By : Dibish
Source: Stackoverflow.com
Question!

Am new to go language, I need to create an Hmac in go language. I have created an Hmac in nodejs, need to generate the same Hamc in go language. Tried following code but getting exactly different output. I dont know what i am doing wrong. This is what I tried

package main

import (
    "crypto/hmac"
    "crypto/sha256"
    "encoding/base64"
    "fmt"
)

func ComputeHmac256(message string, secret string) string {
    key := []byte(secret)
    h := hmac.New(sha256.New, key)
    h.Write([]byte(message))
    return base64.StdEncoding.EncodeToString(h.Sum(nil))
}

func main() {
    fmt.Println(ComputeHmac256("sms1", "b5fb5b3a65b8429693c3a029308e2e46"))
}
Output: JVN7kUPFL0aQ09lIH4YOsFJA3A2faqTuu6zIaYo61VI=

Need go equivalent of following nodejs code

var crypto = require('crypto'),
    text = 'sms1',
    key = 'b5fb5b3a65b8429693c3a029308e2e46'
var hash = crypto.createHmac('sha256', key)
hash.update(text)
var value = hash.digest('hex')
// Output 
25537b9143c52f4690d3d9481f860eb05240dc0d9f6aa4eebbacc8698a3ad552
By : Dibish


Answers

You need to use the same encoding in your Go program as you do in your Node.js program (hex):

package main

import (
    "crypto/hmac"
    "crypto/sha256"
    "encoding/hex"
    "fmt"
)

func ComputeHmac256(message string, secret string) string {
    key := []byte(secret)
    h := hmac.New(sha256.New, key)
    h.Write([]byte(message))
    return hex.EncodeToString(h.Sum(nil))
}

func main() {
    fmt.Println(ComputeHmac256("sms1", "b5fb5b3a65b8429693c3a029308e2e46"))
}

https://play.golang.org/p/-1yePFeipT



Make a Listview and then in its adapter add your table data. Make adapter's layout like this:

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2"            />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="*" />
   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="=" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="4" />

By : VNS


If you are not going to be moving columns around (Friday will always be in whichever cell it is at present and days just continue in sequence to the right) it might be easier to select the entire range to be subject to formatting and HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::

=OR(MOD(COLUMN(),7)=3,MOD(COLUMN(),7)=4)  

Format..., select your choice of Fill, OK, OK.

Adjust 3 and 4 to match whichever day you choose to start the sequence with wherever your selected range starts.

Given information you have withheld of what is where the above might be simplified.

By : pnuts


This video can help you solving your question :)
By: admin