Every line of 'golang sha256' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.
1398 func (x *RemoteDataSource) GetSha256() string { 1399 if x != nil { 1400 return x.Sha256 1401 } 1402 return "" 1403 }
18 func CalcSha256(data ...[]byte) primitives.Sha256 { 19 s := sha256.New() 20 for _, d := range data { 21 s.Write(d) 22 } 23 return s.Sum(nil) 24 }
55 func hashSHA256(str string) string { 56 return fmt.Sprintf("%x", sha256.Sum256([]byte(str))) 57 }
305 func HashAddSha256(builder *flatbuffers.Builder, sha256 flatbuffers.UOffsetT) { 306 builder.PrependUOffsetTSlot(3, flatbuffers.UOffsetT(sha256), 0) 307 }
238 func _sha256(p []byte) []byte { 239 hash := sha256.New() 240 hash.Write(p) 241 s := hash.Sum(nil) 242 if trace { 243 outLogger.Printf("sha length %d value %v", len(s), s) 244 } 245 return s 246 }
10 func NewSHA256(data []byte) []byte { 11 hash := sha256.Sum256(data) 12 return hash[:] 13 }
23 func (ctx *Context) SHA256FromParam(key string) (*cipher.SHA256, error) { 24 if key == "" { 25 return nil, errors.New("Empty key") 26 } 27 value, ok := ctx.parameters[key] 28 if !ok { 29 return nil, ErrorParamNotFound 30 } 31 //logger.Debugf("value: %v", value) 32 33 SHA256, err := cipher.SHA256FromHex(value) 34 if err != nil { 35 return nil, err 36 } 37 //logger.Debugf("SHA256: %v", SHA256.Hex()) 38 39 return &SHA256, nil 40 }
55 func CustomSHA256Hasher() func([]byte) [32]byte { 56 hasher, ok := sha256Pool.Get().(hash.Hash) 57 if !ok { 58 hasher = sha256.New() 59 } else { 60 hasher.Reset() 61 } 62 var h [32]byte 63 64 return func(data []byte) [32]byte { 65 // The hash interface never returns an error, for that reason 66 // we are not handling the error below. For reference, it is 67 // stated here https://golang.org/pkg/hash/#Hash 68 69 // #nosec G104 70 hasher.Write(data) 71 hasher.Sum(h[:0]) 72 hasher.Reset() 73 74 return h 75 } 76 }
58 func main() { 59 b0 := NewBlock( "Hello, Cryptos!", "0000000000000000000000000000000000000000000000000000000000000000" ) 60 b1 := NewBlock( "Hello, Cryptos! - Hello, Cryptos!", b0.Hash ) 61 62 fmt.Println( b0 ) 63 // {1522687834 Hello, Cryptos! 64 // 0000000000000000000000000000000000000000000000000000000000000000 65 // d85da0f449ff9ddc2c5ba638b23b9524381811227eb463b8c9e0be40dc1b1a8a} 66 fmt.Println( len( b0.Hash )) 67 // => 64 68 fmt.Println( len( b0.Prev )) 69 // => 64 70 71 fmt.Println( b1 ) 72 // {1522687834 Hello, Cryptos! - Hello, Cryptos! 73 // d85da0f449ff9ddc2c5ba638b23b9524381811227eb463b8c9e0be40dc1b1a8a 74 // e48ba730165d88e15435483fc3a60714be526096a0c9a71ad10623340e33c7e3} 75 fmt.Println( len( b1.Hash )) 76 // => 64 77 fmt.Println( len( b1.Prev )) 78 // => 64 79 80 blockchain := []Block {b0, b1} 81 fmt.Println( blockchain ) 82 // => [{1522687834 Hello, Cryptos! 83 // 0000000000000000000000000000000000000000000000000000000000000000 84 // d85da0f449ff9ddc2c5ba638b23b9524381811227eb463b8c9e0be40dc1b1a8a} 85 // {1522687834 Hello, Cryptos! - Hello, Cryptos! 86 // d85da0f449ff9ddc2c5ba638b23b9524381811227eb463b8c9e0be40dc1b1a8a 87 // e48ba730165d88e15435483fc3a60714be526096a0c9a71ad10623340e33c7e3}] 88 }
36 func getSha256(data []byte) (string, int64, error) { 37 sha := sha256.New() 38 size, err := sha.Write(data) 39 if err != nil { 40 return "", 0, err 41 } 42 43 id := "sha256:" + hex.EncodeToString(sha.Sum([]byte{})) 44 45 return id, int64(size), nil 46 }