當前位置: 首頁>>代碼示例>>Golang>>正文


Golang data.Key類代碼示例

本文整理匯總了Golang中github.com/endophage/gotuf/data.Key的典型用法代碼示例。如果您正苦於以下問題:Golang Key類的具體用法?Golang Key怎麽用?Golang Key使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Key類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Verify

func (v Ed25519Verifier) Verify(key data.Key, sig []byte, msg []byte) error {
	var sigBytes [ed25519.SignatureSize]byte
	if len(sig) != len(sigBytes) {
		logrus.Infof("signature length is incorrect, must be %d, was %d.", ed25519.SignatureSize, len(sig))
		return ErrInvalid
	}
	copy(sigBytes[:], sig)

	var keyBytes [ed25519.PublicKeySize]byte
	copy(keyBytes[:], key.Public())

	if !ed25519.Verify(&keyBytes, msg, &sigBytes) {
		logrus.Infof("failed ed25519 verification")
		return ErrInvalid
	}
	return nil
}
開發者ID:RichardScothern,項目名稱:notary,代碼行數:17,代碼來源:verifiers.go

示例2: Verify

func (v RSAPemVerifier) Verify(key data.Key, sig []byte, msg []byte) error {
	digest := sha256.Sum256(msg)

	k, _ := pem.Decode([]byte(key.Public()))
	cert, err := x509.ParseCertificate(k.Bytes)
	if err != nil {
		logrus.Errorf("Failed to parse public key: %s\n", err.Error())
		return ErrInvalid
	}

	rsaPub, ok := cert.PublicKey.(*rsa.PublicKey)
	if !ok {
		logrus.Infof("Value returned from ParsePKIXPublicKey was not an RSA public key")
		return ErrInvalid
	}

	if err = rsa.VerifyPKCS1v15(rsaPub, crypto.SHA256, digest[:], sig); err != nil {
		logrus.Errorf("Failed verification: %s", err.Error())
		return ErrInvalid
	}
	return nil
}
開發者ID:aaronlehmann,項目名稱:notary,代碼行數:22,代碼來源:verifiers.go

示例3: Verify

func (v RSAVerifier) Verify(key data.Key, sig []byte, msg []byte) error {
	digest := sha256.Sum256(msg)
	keyReader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(key.Public()))
	keyBytes, _ := ioutil.ReadAll(keyReader)
	pub, err := x509.ParsePKIXPublicKey(keyBytes)
	if err != nil {
		logrus.Infof("Failed to parse public key: %s\n", err)
		return ErrInvalid
	}

	rsaPub, ok := pub.(*rsa.PublicKey)
	if !ok {
		logrus.Infof("Value returned from ParsePKIXPublicKey was not an RSA public key")
		return ErrInvalid
	}

	if err = rsa.VerifyPKCS1v15(rsaPub, crypto.SHA256, digest[:], sig); err != nil {
		logrus.Infof("Failed verification: %s", err)
		return ErrInvalid
	}
	return nil
}
開發者ID:progrium,項目名稱:notary,代碼行數:22,代碼來源:verifiers.go


注:本文中的github.com/endophage/gotuf/data.Key類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。