Last active
August 18, 2016 09:14
-
-
Save guange2015/6a5ce54f8fa3890e4ab32e8f71b00b5c to your computer and use it in GitHub Desktop.
ether password test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/hex" | |
"flag" | |
"github.com/ethereum/go-ethereum/crypto" | |
"golang.org/x/crypto/scrypt" | |
"log" | |
) | |
func main() { | |
const ( | |
SALT_HEX = "d42e9ef41c1f4b0b020cbe89ac4a37b9922861379da6775fdd7da598aba1ba42" | |
CIPHER_HEX = "be849afadeb2db97f208c40a1b47d9de7754d884c05bce06251fd1cb47333d85" | |
MAC_HEX = "86d84ee41178e49d29ca552575a83b7d8e2a6fd7d5351a6425cc1d5fc901ac09" | |
) | |
var password = flag.String("password", "123456", "help message for flagname") | |
flag.Parse() | |
salt, _ := hex.DecodeString(SALT_HEX) | |
dk, err := scrypt.Key([]byte(*password), salt, 262144, 8, 1, 32) | |
if err != nil { | |
log.Fatal(err) | |
} | |
cipherText, _ := hex.DecodeString(CIPHER_HEX) //ciphertext | |
calculatedMAC := crypto.Keccak256(dk[16:32], cipherText) | |
mac, _ := hex.DecodeString(MAC_HEX) //mac | |
if bytes.Equal(calculatedMAC, mac) { | |
log.Println("equal") | |
} else { | |
log.Println("error") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment