本文整理匯總了Golang中crypto/sha512.Sum512函數的典型用法代碼示例。如果您正苦於以下問題:Golang Sum512函數的具體用法?Golang Sum512怎麽用?Golang Sum512使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Sum512函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DecryptV2
/*
對稱解密,
不會修改輸入的數據
*/
func DecryptV2(key []byte, data []byte) (output []byte, err error) {
if len(data) < 16+64 {
return nil, errors.New("[kmgCipher.Decrypt] input data too small")
}
keyHash := sha512.Sum512(key)
aseKey := keyHash[:32]
cbcIv := data[:16]
block, err := aes.NewCipher(aseKey)
if err != nil {
return nil, err
}
if len(data)%block.BlockSize() != 0 {
return nil, errors.New("[kmgCipher.Decrypt] input not full blocks")
}
output = make([]byte, len(data)-16)
blockmode := cipher.NewCBCDecrypter(block, cbcIv)
blockmode.CryptBlocks(output, data[16:])
paddingSize := int(output[len(output)-1])
if paddingSize > block.BlockSize() {
return nil, errors.New("[kmgCipher.Decrypt] paddingSize out of range")
}
beforeCbcSize := len(data) - paddingSize - 64 - 16
hashData := sha512.Sum512(output[:beforeCbcSize])
if !bytes.Equal(hashData[:], output[beforeCbcSize:beforeCbcSize+64]) {
return nil, errors.New("[kmgCipher.Decrypt] hash not match")
}
return output[:beforeCbcSize], nil
}
示例2: CalcVector
func CalcVector(p []byte) InvVector {
sum := sha512.Sum512(p)
sum = sha512.Sum512(sum[:])
var v InvVector
copy(v[:], sum[:32])
return v
}
示例3: EncodePasswd
// EncodePasswd encodes password to safe format.
func (u *User) EncodePasswd() {
hash := []byte(u.Passwd)
dig := sha512.Sum512(hash)
for i := 1; i < 5000; i++ {
dig = sha512.Sum512(append(dig[:], hash[:]...))
}
newPasswd := base64.StdEncoding.EncodeToString(dig[:])
u.Passwd = fmt.Sprintf("%s", newPasswd)
}
示例4: VerifyRoll
// VerifyRoll verifies an Intus.co roll is fair.
func VerifyRoll(r *Roll) error {
serverHash, err := hex.DecodeString(r.ServerHash)
if err != nil {
return err
}
serverRand, err := hex.DecodeString(r.ServerRand)
if err != nil {
return err
}
// Does serverRand hash match?
calcServerHash := sha512.Sum512(serverRand)
if !bytes.Equal(calcServerHash[:], serverHash) {
return errors.New("serverRand does not match serverHash")
}
log.Println("server hashes match")
// Calculate roll value matches.
clientRand, err := hex.DecodeString(r.ClientRand)
if err != nil {
return err
}
// Concatenate serverRand and clientRand.
combRand := append(serverRand, clientRand...)
// Hash the result.
combHash := sha512.Sum512(combRand)
// Determine the integer value of combHash.
combValue := new(big.Int).SetBytes(combHash[:])
// Now mod the winValue and value to get the provably fair rollValue that is
// of range of [0, r.WinValue).
rollValue := new(big.Int)
new(big.Int).DivMod(combValue, big.NewInt(r.WinValue), rollValue)
// Check roll values match.
if rollValue.Int64() != r.RollValue {
return errors.New("roll values do not match")
}
log.Printf("roll value calculated at %v", rollValue)
// Now see if the roll was a winning one.
if rollValue.Int64() < r.BetValue {
log.Printf("provably fair win of %v Satoshi", r.WinValue)
} else {
log.Printf("provably fair loss of %v Satoshi", r.BetValue)
}
return nil
}
示例5: shaHash
func shaHash(fl string, a string) {
if fl == "t" {
fmt.Print("SHA384 Hash Value:\n")
fmt.Printf("%x\n", sha512.Sum512([]byte(a)))
} else if fl == "f" {
fmt.Print("SHA512 Hash Value:\n")
fmt.Printf("%x\n", sha512.Sum512([]byte(a)))
} else {
fmt.Print("SHA256 Hash Value:\n")
fmt.Printf("%x\n", sha256.Sum256([]byte(a)))
}
}
示例6: SHA512
// SHA512 sum for the given password. If a SaltConf
// pointer is given as a parameter a salt with the given
// length will be returned with it included in the hash.
func (p *Password) SHA512(saltConf ...*SaltConf) ([64]byte, []byte) {
if len(saltConf) > 0 {
var saltLength int
for _, i := range saltConf[0:] {
saltLength = i.Length
}
salt := getRandomBytes(saltLength)
return sha512.Sum512([]byte(fmt.Sprintf("%s%x", p.Pass, salt))), salt
}
return sha512.Sum512([]byte(p.Pass)), nil
}
示例7: handle
func handle(w http.ResponseWriter, r *http.Request) {
currentTime := time.Now().Unix()
res := response{
Time: currentTime,
Hash: fmt.Sprintf("%x", sha512.Sum512([]byte(trueRemoteAddr(r)))),
ClientIP: trueRemoteAddr(r),
}
resj, _ := json.Marshal(res)
etag := fmt.Sprintf("\"%x\"", sha512.Sum512(resj))
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Etag", etag)
w.Write(resj)
}
示例8: main
func main() {
usage := "Usage: echo -n hello | ./ex02 [256|384|512]"
bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
n := 256
if len(os.Args) == 2 {
n, _ = strconv.Atoi(os.Args[1])
}
switch n {
case 256:
fmt.Printf("%x\n", sha256.Sum256(bytes))
os.Exit(0)
return
case 384:
fmt.Printf("%x\n", sha512.Sum384(bytes))
os.Exit(0)
return
case 512:
fmt.Printf("%x\n", sha512.Sum512(bytes))
os.Exit(0)
return
default:
fmt.Println(usage)
os.Exit(1)
return
}
}
示例9: cmdAdd
func cmdAdd(args *skel.CmdArgs) error {
conf := NetConf{}
if err := json.Unmarshal(args.StdinData, &conf); err != nil {
return fmt.Errorf("failed to load netconf: %v", err)
}
// run the IPAM plugin and get back the config to apply
result, err := plugin.ExecAdd(conf.IPAM.Type, args.StdinData)
if err != nil {
return err
}
if result.IP4 == nil {
return errors.New("IPAM plugin returned missing IPv4 config")
}
hostVethName, err := setupContainerVeth(args.Netns, args.IfName, conf.MTU, result)
if err != nil {
return err
}
if err = setupHostVeth(hostVethName, result.IP4); err != nil {
return err
}
if conf.IPMasq {
h := sha512.Sum512([]byte(args.Netns))
chain := fmt.Sprintf("CNI-%s-%x", conf.Name, h[:8])
if err = ip.SetupIPMasq(&result.IP4.IP, chain); err != nil {
return err
}
}
return plugin.PrintResult(result)
}
示例10: init
func init() {
var filename string
var err error
flag.StringVar(&filename, "file", "key.txt",
"file containing secret key")
flag.Parse()
f, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
b := sha512.Sum512(f)
key, err = ecdsa.GenerateKey(elliptic.P256(), bytes.NewReader(b[:]))
if err != nil {
panic(err)
}
err = rs.Open("./test.db", key)
if err != nil {
panic(err)
}
m = new(mic.Reader)
go func() {
for {
var bits [32]byte
m.Read(bits[:])
_, err := rs.New(bits)
if err != nil {
fmt.Printf("error making record %s\n", err)
}
time.Sleep(60 * time.Second)
}
}()
}
示例11: CalcSharedSecret
// CalcSharedSecret does a triple DH from the keypacks to generate the shared secret. myKeys needs to contain private keys, peerKeys only needs public keys
// Sending determines if one is sender or recipient of a message.
func CalcSharedSecret(myKeys, peerKeys *KeyPack, nonce *[NonceSize]byte, sending bool) (sharedSecret [SharedKeySize]byte) {
preKey := make([]byte, 3*Curve25519KeySize+NonceSize) // three keys plus nonce
key1, key2, key3 := new(Curve25519Key), new(Curve25519Key), new(Curve25519Key)
log.Secretf("TemporaryPrivKey: %x\n", *myKeys.TemporaryPrivKey)
log.Secretf("ConstantPrivKey: %x\n", *myKeys.ConstantPrivKey)
log.Secretf("TemporaryPubKey: %x\n", *peerKeys.TemporaryPubKey)
log.Secretf("ConstantPubKey: %x\n", *peerKeys.ConstantPubKey)
scalarMult(key1, myKeys.TemporaryPrivKey, peerKeys.TemporaryPubKey)
log.Secretf("Key1: %x\n", *key1)
scalarMult(key2, myKeys.ConstantPrivKey, peerKeys.TemporaryPubKey)
scalarMult(key3, myKeys.TemporaryPrivKey, peerKeys.ConstantPubKey)
preKey = append(preKey, key1[:]...)
if sending {
log.Secretf("Key2: %x\n", *key2)
log.Secretf("Key3: %x\n", *key3)
preKey = append(preKey, key2[:]...)
preKey = append(preKey, key3[:]...)
} else { // Swap for receiver
log.Secretf("Key2: %x\n", *key3)
log.Secretf("Key3: %x\n", *key2)
preKey = append(preKey, key3[:]...)
preKey = append(preKey, key2[:]...)
}
log.Secretf("Nonce: %x\n", *nonce)
preKey = append(preKey, nonce[:]...)
return sha512.Sum512(preKey)
}
示例12: _passpharseHash
func _passpharseHash(passpharse []byte, encodingWay []string) (encodedpasspharse []byte) {
encodepasspharse := passpharse
for _, hashalgor := range encodingWay {
switch hashalgor {
case "md5":
sum := md5.Sum(encodepasspharse)
encodepasspharse = sum[:]
case "sha1":
sum := sha1.Sum(encodepasspharse)
encodepasspharse = sum[:]
case "sha224":
sum := sha256.Sum224(encodepasspharse)
encodepasspharse = sum[:]
case "sha256":
sum := sha256.Sum256(encodepasspharse)
encodepasspharse = sum[:]
case "sha384":
sum := sha512.Sum384(encodepasspharse)
encodepasspharse = sum[:]
case "sha512":
sum := sha512.Sum512(encodepasspharse)
encodepasspharse = sum[:]
}
}
//issue if return with not args,the return value will be null
return encodepasspharse
}
示例13: Hash
// Hash takes an array of strings and returns their hash.
func Hash(strings ...string) (string, error) {
var bytes []byte
for _, s := range strings {
bytes = append(bytes, []byte(s)...)
}
return fmt.Sprintf("%s%x", "sha512-", sha512.Sum512(bytes)), nil
}
示例14: createAttachment
func createAttachment(content_type, fname string, body io.Reader) NNTPAttachment {
media_type, _, err := mime.ParseMediaType(content_type)
if err == nil {
a := nntpAttachment{}
_, err = io.Copy(&a.body, body)
if err == nil {
a.header = make(textproto.MIMEHeader)
a.mime = media_type + "; charset=UTF-8"
idx := strings.LastIndex(fname, ".")
a.ext = ".txt"
if idx > 0 {
a.ext = fname[idx:]
}
a.header.Set("Content-Disposition", `form-data; filename="`+fname+`"; name="attachment"`)
a.header.Set("Content-Type", a.mime)
a.header.Set("Content-Transfer-Encoding", "base64")
h := sha512.Sum512(a.body.Bytes())
hashstr := base32.StdEncoding.EncodeToString(h[:])
a.hash = h[:]
a.filepath = hashstr + a.ext
a.filename = fname
return a
}
}
return nil
}
示例15: cmdDel
func cmdDel(args *skel.CmdArgs) error {
conf := NetConf{}
if err := json.Unmarshal(args.StdinData, &conf); err != nil {
return fmt.Errorf("failed to load netconf: %v", err)
}
var ipn *net.IPNet
err := ns.WithNetNSPath(args.Netns, false, func(hostNS *os.File) error {
var err error
ipn, err = ip.DelLinkByNameAddr(args.IfName, netlink.FAMILY_V4)
return err
})
if err != nil {
return err
}
if conf.IPMasq {
h := sha512.Sum512([]byte(args.ContainerID))
chain := fmt.Sprintf("CNI-%s-%x", conf.Name, h[:8])
if err = ip.TeardownIPMasq(ipn, chain); err != nil {
return err
}
}
return ipam.ExecDel(conf.IPAM.Type, args.StdinData)
}