本文整理汇总了Golang中crypto/sha256.New224函数的典型用法代码示例。如果您正苦于以下问题:Golang New224函数的具体用法?Golang New224怎么用?Golang New224使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New224函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: sha224
func (e *Engine) sha224() error {
data, err := computeHash(sha256.New224(), e.stack.Pop())
if err == nil {
e.stack.Push(data)
}
return err
}
开发者ID:ancientlore,项目名称:hashsrv,代码行数:7,代码来源:hash.go
示例2: Encrypt
// Encrypts a symmetric key to this identity
func (this *PublicIdentity) Encrypt(key *SymmetricKey) (ek *EncryptedKey) {
out, err := rsa.EncryptOAEP(sha256.New224(), rand.Reader, this.key, key.key, nil)
if err != nil {
panic(err)
}
return &EncryptedKey{impl: out}
}
开发者ID:Javantea,项目名称:h0tb0x,代码行数:8,代码来源:crypto.go
示例3: process_file
func process_file(filename string, complete chan Sumlist) {
sumlist := Sumlist{}
sumlist.filename = filename
// Open the file and bail if we fail
infile, err := os.Open(filename)
if err != nil {
log.Printf("Unable to open %s: %s", filename, err)
complete <- sumlist
return
}
defer infile.Close()
// Create the checksum objects
if flag_crc32 {
sumlist.sums = append(sumlist.sums, Checksum{"CRC32", crc32.New(crc32.IEEETable)})
}
if flag_crc64 {
sumlist.sums = append(sumlist.sums, Checksum{"CRC64", crc64.New(crc64.MakeTable(crc64.ISO))})
}
if flag_sha224 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA224", sha256.New224()})
}
if flag_sha256 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA256", sha256.New()})
}
if flag_sha384 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA384", sha512.New384()})
}
if flag_sha512 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA512", sha512.New()})
}
// Create our file reader
reader := bufio.NewReader(infile)
// Start a buffer and loop to read the entire file
buf := make([]byte, 4096)
for {
read_count, err := reader.Read(buf)
// If we get an error that is not EOF, then we have a problem
if err != nil && err != io.EOF {
log.Printf("Unable to open %s: %s", filename, err)
complete <- sumlist
return
}
// If the returned size is zero, we're at the end of the file
if read_count == 0 {
break
}
// Add the buffer contents to the checksum calculation
for _, sum := range sumlist.sums {
sum.hashFunc.Write(buf[:read_count])
}
}
complete <- sumlist
}
开发者ID:joerocklin,项目名称:qhash,代码行数:60,代码来源:qhash.go
示例4: Checksum
// Checksum returns the checksum of some data, using a specified algorithm.
// It only returns an error when an invalid algorithm is used. The valid ones
// are MD5, SHA1, SHA224, SHA256, SHA384, SHA512, SHA3224, SHA3256, SHA3384,
// and SHA3512.
func Checksum(algorithm string, data []byte) (checksum string, err error) {
// default
var hasher hash.Hash
switch strings.ToUpper(algorithm) {
case "MD5":
hasher = md5.New()
case "SHA1":
hasher = sha1.New()
case "SHA224":
hasher = sha256.New224()
case "SHA256":
hasher = sha256.New()
case "SHA384":
hasher = sha512.New384()
case "SHA512":
hasher = sha512.New()
case "SHA3224":
hasher = sha3.New224()
case "SHA3256":
hasher = sha3.New256()
case "SHA3384":
hasher = sha3.New384()
case "SHA3512":
hasher = sha3.New512()
default:
msg := "Invalid algorithm parameter passed go Checksum: %s"
return checksum, fmt.Errorf(msg, algorithm)
}
hasher.Write(data)
str := hex.EncodeToString(hasher.Sum(nil))
return str, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:36,代码来源:fsstatus.go
示例5: Decrypt
// Decrypts a symmetric key encrypted to this Identity
func (this *SecretIdentity) Decrypt(ek *EncryptedKey) (key *SymmetricKey) {
out, err := rsa.DecryptOAEP(sha256.New224(), rand.Reader, this.key, ek.impl, nil)
if err != nil {
panic(err)
}
return &SymmetricKey{key: out}
}
开发者ID:Javantea,项目名称:h0tb0x,代码行数:8,代码来源:crypto.go
示例6: main
func main() {
for _, h := range []hash.Hash{md4.New(), md5.New(), sha1.New(),
sha256.New224(), sha256.New(), sha512.New384(), sha512.New(),
ripemd160.New()} {
fmt.Printf("%x\n\n", h.Sum())
}
}
开发者ID:sbhackerspace,项目名称:sbhx-snippets,代码行数:7,代码来源:hash.go
示例7: Sha224base64
// Sha224base64 performs a sha224 hash on a byte array and then perfroms a base64 encoding on the result.
func Sha224base64(item []byte) (string, []byte) {
phash := sha256.New224()
io.WriteString(phash, string(item))
phashbytes := phash.Sum(nil)
return base64.StdEncoding.EncodeToString(phashbytes), phashbytes
}
开发者ID:rputbl,项目名称:hashbase,代码行数:8,代码来源:hashbase.go
示例8: hash
func hash(pass string, salt_secret string, salt string, interation int64) (string, error) {
var pass_salt string = salt_secret + pass + salt + salt_secret + pass + salt + pass + pass + salt
var i int
hash_pass := salt_local_secret
hash_start := sha512.New()
hash_center := sha256.New()
hash_output := sha256.New224()
i = 0
for i <= stretching_password {
i = i + 1
hash_start.Write([]byte(pass_salt + hash_pass))
hash_pass = hex.EncodeToString(hash_start.Sum(nil))
}
i = 0
for int64(i) <= interation {
i = i + 1
hash_pass = hash_pass + hash_pass
}
i = 0
for i <= stretching_password {
i = i + 1
hash_center.Write([]byte(hash_pass + salt_secret))
hash_pass = hex.EncodeToString(hash_center.Sum(nil))
}
hash_output.Write([]byte(hash_pass + salt_local_secret))
hash_pass = hex.EncodeToString(hash_output.Sum(nil))
return hash_pass, nil
}
开发者ID:vzglad-smerti,项目名称:password_hash,代码行数:33,代码来源:password.go
示例9: calc_checksum
/*
read from os.File and return the whole file's checksum
*/
func calc_checksum(fp io.Reader, t string) string {
var m hash.Hash
switch t {
case "md5":
m = md5.New()
case "sha1":
m = sha1.New()
case "sha512":
m = sha512.New()
case "sha256":
m = sha256.New()
case "sha224":
m = sha256.New224()
case "sha384":
m = sha512.New384()
default:
output_e("unknown type: %s\n", t)
return ""
}
/* issue:
if fp is os.Stdin, there is no way to trigger EOF
*/
_, err := io.Copy(m, fp)
if err != nil {
output_e("%ssum: %s\n", t, err.Error())
return ""
}
return fmt.Sprintf("%x", m.Sum(nil))
}
开发者ID:patrickToca,项目名称:go-coreutils,代码行数:35,代码来源:calc_sum.go
示例10: Sha224Sum
func Sha224Sum(rdr io.Reader) (hash []byte, err error) {
s224 := sha256.New224()
if _, err = io.Copy(s224, rdr); err != nil {
return
}
hash = make([]byte, 0, sha256.Size224)
hash = s224.Sum(hash)
return
}
开发者ID:zaolab,项目名称:sunnified,代码行数:9,代码来源:util.go
示例11: Fingerprint
// Computes a cryptographic fingerprint of this identity
func (this *PublicIdentity) Fingerprint() (fingerprint *Digest) {
hash := sha256.New224()
data, err := x509.MarshalPKIXPublicKey(this.key)
if err != nil {
panic(err)
}
hash.Write(data)
return &Digest{impl: hash.Sum(nil)}
}
开发者ID:Javantea,项目名称:h0tb0x,代码行数:10,代码来源:crypto.go
示例12: TestSize
func TestSize(t *testing.T) {
c := sha256.New()
if got := c.Size(); got != Size {
t.Errorf("Size = %d; want %d", got, sha256.Size)
}
c = sha256.New224()
if got := c.Size(); got != Size224 {
t.Errorf("New224.Size = %d; want %d", got, sha256.Size224)
}
}
开发者ID:rachtsingh,项目名称:gogojuice,代码行数:10,代码来源:sha256_test.go
示例13: pathHashWrite
func (b *backend) pathHashWrite(
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
inputB64 := d.Get("input").(string)
format := d.Get("format").(string)
algorithm := d.Get("urlalgorithm").(string)
if algorithm == "" {
algorithm = d.Get("algorithm").(string)
}
input, err := base64.StdEncoding.DecodeString(inputB64)
if err != nil {
return logical.ErrorResponse(fmt.Sprintf("unable to decode input as base64: %s", err)), logical.ErrInvalidRequest
}
switch format {
case "hex":
case "base64":
default:
return logical.ErrorResponse(fmt.Sprintf("unsupported encoding format %s; must be \"hex\" or \"base64\"", format)), nil
}
var hf hash.Hash
switch algorithm {
case "sha2-224":
hf = sha256.New224()
case "sha2-256":
hf = sha256.New()
case "sha2-384":
hf = sha512.New384()
case "sha2-512":
hf = sha512.New()
default:
return logical.ErrorResponse(fmt.Sprintf("unsupported algorithm %s", algorithm)), nil
}
hf.Write(input)
retBytes := hf.Sum(nil)
var retStr string
switch format {
case "hex":
retStr = hex.EncodeToString(retBytes)
case "base64":
retStr = base64.StdEncoding.EncodeToString(retBytes)
}
// Generate the response
resp := &logical.Response{
Data: map[string]interface{}{
"sum": retStr,
},
}
return resp, nil
}
开发者ID:quixoten,项目名称:vault,代码行数:53,代码来源:path_hash.go
示例14: GetHash
func GetHash(a string) (hash.Hash, error) {
var h hash.Hash
switch a {
case "adler32":
h = adler32.New()
case "crc32", "crc32ieee":
h = crc32.New(crc32.MakeTable(crc32.IEEE))
case "crc32castagnoli":
h = crc32.New(crc32.MakeTable(crc32.Castagnoli))
case "crc32koopman":
h = crc32.New(crc32.MakeTable(crc32.Koopman))
case "crc64", "crc64iso":
h = crc64.New(crc64.MakeTable(crc64.ISO))
case "crc64ecma":
h = crc64.New(crc64.MakeTable(crc64.ECMA))
case "fnv", "fnv32":
h = fnv.New32()
case "fnv32a":
h = fnv.New32a()
case "fnv64":
h = fnv.New64()
case "fnv64a":
h = fnv.New64a()
case "hmac", "hmacsha256":
h = hmac.New(sha256.New, []byte(key))
case "hmacmd5":
h = hmac.New(md5.New, []byte(key))
case "hmacsha1":
h = hmac.New(sha1.New, []byte(key))
case "hmacsha512":
h = hmac.New(sha512.New, []byte(key))
case "md4":
h = md4.New()
case "md5":
h = md5.New()
case "ripemd160":
h = ripemd160.New()
case "sha1":
h = sha1.New()
case "sha224":
h = sha256.New224()
case "sha256":
h = sha256.New()
case "sha384":
h = sha512.New384()
case "sha512":
h = sha512.New()
default:
return nil, errors.New("Invalid algorithm")
}
return h, nil
}
开发者ID:patrickmn,项目名称:picugen,代码行数:52,代码来源:picugen.go
示例15: getHashSHA2
func getHashSHA2(bitsize int) (hash.Hash, error) {
switch bitsize {
case 224:
return sha256.New224(), nil
case 256:
return sha256.New(), nil
case 384:
return sha512.New384(), nil
case 512:
return sha512.New(), nil
case 521:
return sha512.New(), nil
default:
return nil, fmt.Errorf("Invalid bitsize. It was [%d]. Expected [224, 256, 384, 512, 521]", bitsize)
}
}
开发者ID:C0rWin,项目名称:fabric,代码行数:16,代码来源:hash.go
示例16: cryptoSHA2Example
func cryptoSHA2Example() {
h224 := sha256.New224()
io.WriteString(h224, "foo")
h256 := sha256.New()
io.WriteString(h256, "foo")
h384 := sha512.New384()
io.WriteString(h384, "foo")
h512 := sha512.New()
io.WriteString(h512, "foo")
fmt.Printf("SHA224 %x\n", h224.Sum(nil))
fmt.Printf("SHA256 %x\n", h256.Sum(nil))
fmt.Printf("SHA384 %x\n", h384.Sum(nil))
fmt.Printf("SHA512 %x\n", h512.Sum(nil))
}
开发者ID:kyokomi-sandbox,项目名称:sandbox,代码行数:16,代码来源:crypto.go
示例17: printHashes
func printHashes(input io.Reader) {
var md5writer hash.Hash = nil
if *printmd5hash == false {
md5writer = md5.New()
}
var sha1writer hash.Hash = nil
if *printsha1hash == false {
sha1writer = sha1.New()
}
var sha224writer hash.Hash = nil
if *printsha224hash == false {
sha224writer = sha256.New224()
}
var sha256writer hash.Hash = nil
if *printsha256hash == false {
sha256writer = sha256.New()
}
var sha384writer hash.Hash = nil
if *printsha384hash == false {
sha384writer = sha512.New384()
}
var sha512writer hash.Hash = nil
if *printsha512hash == false {
sha512writer = sha512.New()
}
hashwriter := NilSafeMultiWriter(md5writer, sha1writer, sha224writer, sha256writer, sha384writer, sha512writer)
io.Copy(hashwriter, input)
if md5writer != nil {
fmt.Printf(" -md5 %x", md5writer.Sum(nil))
}
if sha1writer != nil {
fmt.Printf(" -sha1 %x", sha1writer.Sum(nil))
}
if sha224writer != nil {
fmt.Printf(" -sha224 %x", sha224writer.Sum(nil))
}
if sha256writer != nil {
fmt.Printf(" -sha256 %x", sha256writer.Sum(nil))
}
if sha384writer != nil {
fmt.Printf(" -sha384 %x", sha384writer.Sum(nil))
}
if sha512writer != nil {
fmt.Printf(" -sha512 %x", sha512writer.Sum(nil))
}
fmt.Print("\n")
}
开发者ID:schoentoon,项目名称:hashcheck,代码行数:47,代码来源:printhashes.go
示例18: TestGolden
func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ {
g := golden[i]
s := fmt.Sprintf("%x", sha256.Sum256([]byte(g.in)))
if s != g.out {
t.Fatalf("Sum256 function: sha256(%s) = %s want %s", g.in, s, g.out)
}
c := sha256.New()
for j := 0; j < 3; j++ {
if j < 2 {
io.WriteString(c, g.in)
} else {
io.WriteString(c, g.in[0:len(g.in)/2])
c.Sum(nil)
io.WriteString(c, g.in[len(g.in)/2:])
}
s := fmt.Sprintf("%x", c.Sum(nil))
if s != g.out {
t.Fatalf("sha256[%d](%s) = %s want %s", j, g.in, s, g.out)
}
c.Reset()
}
}
for i := 0; i < len(golden224); i++ {
g := golden224[i]
s := fmt.Sprintf("%x", sha256.Sum224([]byte(g.in)))
if s != g.out {
t.Fatalf("Sum224 function: sha224(%s) = %s want %s", g.in, s, g.out)
}
c := sha256.New224()
for j := 0; j < 3; j++ {
if j < 2 {
io.WriteString(c, g.in)
} else {
io.WriteString(c, g.in[0:len(g.in)/2])
c.Sum(nil)
io.WriteString(c, g.in[len(g.in)/2:])
}
s := fmt.Sprintf("%x", c.Sum(nil))
if s != g.out {
t.Fatalf("sha224[%d](%s) = %s want %s", j, g.in, s, g.out)
}
c.Reset()
}
}
}
开发者ID:rachtsingh,项目名称:gogojuice,代码行数:46,代码来源:sha256_test.go
示例19: GenerateChallenge
func GenerateChallenge(
/* to verify */ A *rsa.PublicKey,
/* ours*/ B *rsa.PublicKey) (Challenge, [32]byte, error) {
// variables
var challenge Challenge
var r [32]byte
var err error
// encode b
copy(challenge.PubKey[:], crypto.MarshalPKCS1PublicKey(B))
if err != nil {
log.Fatalln("Auth.GenerateChallenge: cannot marshall public key b, error: " + err.Error())
}
// generate r
_, err = rand.Read(r[:])
if err != nil {
log.Fatalln("Auth.GenerateChallenge: cannot get secure random number, error: " + err.Error())
}
//fmt.Printf("r: %.x\n", r)
// get h(r)
challenge.HR = sha256.Sum256(r[:])
{ // get P_A(r,B)
buf := make([]byte, 64)
copy(buf[0:32], r[:])
hb := sha256.Sum256(challenge.PubKey[:])
copy(buf[32:64], hb[:])
// encrypt (r,h(B))
enc, err := rsa.EncryptOAEP(
sha256.New224(), /* hash function */
rand.Reader, /* random source */
A, /* encryption key */
buf, /* plaintext */
[]byte{}) /* label */
if err != nil {
return challenge, r, errors.New("Auth.GenerateChallenge: Could not encrypt (r,B), due to " + err.Error())
}
challenge.Enc = enc
}
// fill challenge struct
return challenge, r, nil
}
开发者ID:Zwiebelring,项目名称:zwiebelnetz,代码行数:46,代码来源:challenge_response.go
示例20: SaveThumbnailAndImage
func SaveThumbnailAndImage(imgr io.ReadSeeker, maxw, maxh int, tdir, dir, fname string) (tname, name string, err error) {
var resized bool
tname, resized, err = saveThumbnail(imgr, maxw, maxh, tdir, fname)
if err != nil {
return
}
var source io.Reader
var file *os.File
if resized {
imgr.Seek(0, 0)
var s224 = sha256.New224()
if _, err = io.Copy(s224, imgr); err != nil {
return
}
hash := make([]byte, 0, sha256.Size224)
hash = s224.Sum(hash)
name = fmt.Sprintf("%x%s", hash, path.Ext(tname))
imgr.Seek(0, 0)
if _, err = os.Stat(dir + name); err == nil {
return
} else if !os.IsNotExist(err) {
return
}
source = imgr
} else {
var sourcefile *os.File
if sourcefile, err = os.Open(util.AddDirTrailSlash(tdir) + tname); err != nil {
return
}
defer sourcefile.Close()
source = sourcefile
name = tname
}
if file, err = os.Create(dir + name); err != nil {
return
}
defer file.Close()
_, err = io.Copy(file, source)
return
}
开发者ID:zaolab,项目名称:sunnified,代码行数:46,代码来源:img.go
注:本文中的crypto/sha256.New224函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论