当前位置: 首页>>代码示例>>Golang>>正文


Golang rsa.SignPSS函数代码示例

本文整理汇总了Golang中crypto/rsa.SignPSS函数的典型用法代码示例。如果您正苦于以下问题:Golang SignPSS函数的具体用法?Golang SignPSS怎么用?Golang SignPSS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SignPSS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Sign

// Implements the Sign method from SigningMethod
// For this signing method, key must be an rsa.PrivateKey struct
func (m *SigningMethodRSAPSS) Sign(signingString string, key interface{}) (string, error) {
	var rsaKey *rsa.PrivateKey

	switch k := key.(type) {
	case *rsa.PrivateKey:
		rsaKey = k
	default:
		return "", ErrInvalidKey
	}

	// Create the hasher
	if !m.Hash.Available() {
		return "", ErrHashUnavailable
	}

	hasher := m.Hash.New()
	hasher.Write([]byte(signingString))

	// Sign the string and return the encoded bytes
	if sigBytes, err := rsa.SignPSS(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil), m.Options); err == nil {
		return EncodeSegment(sigBytes), nil
	} else {
		return "", err
	}
}
开发者ID:CadeLaRen,项目名称:traffic_control,代码行数:27,代码来源:rsa_pss.go

示例2: Sign

func (alg *RsaPssUsingSha) Sign(securedInput []byte, key interface{}) (signature []byte, err error) {
	if privKey, ok := key.(*rsa.PrivateKey); ok {
		return rsa.SignPSS(rand.Reader, privKey, hashFunc(alg.keySizeBits), sha(alg.keySizeBits, securedInput), &rsa.PSSOptions{SaltLength: alg.saltSizeBytes})
	}

	return nil, errors.New("RsaPssUsingSha.Sign(): expects key to be '*rsa.PrivateKey'")
}
开发者ID:useidel,项目名称:notary,代码行数:7,代码来源:rsapss_using_sha.go

示例3: PayloadSign

// Sign generates a sign based on the Algorithm instance variable.
// This fulfills the `Signer` interface
func (s RsaSign) PayloadSign(payload []byte) ([]byte, error) {
	hash, err := rsaHashForAlg(s.SignatureAlgorithm())
	if err != nil {
		return nil, ErrUnsupportedAlgorithm
	}

	privkey := s.PrivateKey
	if privkey == nil {
		return nil, ErrMissingPrivateKey
	}

	h := hash.New()
	h.Write(payload)

	switch s.SignatureAlgorithm() {
	case jwa.RS256, jwa.RS384, jwa.RS512:
		return rsa.SignPKCS1v15(rand.Reader, privkey, hash, h.Sum(nil))
	case jwa.PS256, jwa.PS384, jwa.PS512:
		return rsa.SignPSS(rand.Reader, privkey, hash, h.Sum(nil), &rsa.PSSOptions{
			SaltLength: rsa.PSSSaltLengthAuto,
		})
	default:
		return nil, ErrUnsupportedAlgorithm
	}
}
开发者ID:nabeken,项目名称:go-jwx,代码行数:27,代码来源:signer.go

示例4: Sign

// Sign generates a digital signature of the message passed in.
func Sign(prv *rsa.PrivateKey, m []byte) (sig []byte, err error) {
	h := sha256.New()
	h.Write(m)
	d := h.Sum(nil)
	sig, err = rsa.SignPSS(rand.Reader, prv, crypto.SHA256, d, nil)
	return
}
开发者ID:jonathanmarvens,项目名称:gocrypto,代码行数:8,代码来源:crypto.go

示例5: sign

func sign(prv *rsa.PrivateKey, msg string) (signature string, err error) {
	h := sha256.New()
	h.Write([]byte(msg))
	d := h.Sum(nil)
	sigBin, _ := rsa.SignPSS(rand.Reader, prv, crypto.SHA256, d, nil)
	signature = encodeBase64(sigBin)
	return
}
开发者ID:nicnys-8,项目名称:mdc,代码行数:8,代码来源:crypto.go

示例6: SignMessageWithKey

func SignMessageWithKey(key *rsa.PrivateKey, msg string) (sig []byte, err error) {
	hashFunction := sha256.New()
	io.WriteString(hashFunction, msg)
	hashSum := hashFunction.Sum(nil)

	sig, err = rsa.SignPSS(rand.Reader, key, crypto.SHA256, hashSum, nil)
	return
}
开发者ID:omarqazi,项目名称:logistics,代码行数:8,代码来源:auth.go

示例7: BenchmarkRsaSign

func BenchmarkRsaSign(b *testing.B) {
	key, _ := rsa.GenerateKey(rand.Reader, 2048)
	val := sha256.Sum256(make([]byte, 32, 32))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		rsa.SignPSS(rand.Reader, key, crypto.SHA256, val[:], nil)
	}
}
开发者ID:hyperledger,项目名称:fabric,代码行数:9,代码来源:testsys_test_test.go

示例8: signMessage

func (r *rsaPSSSigner) signMessage(key crypto.PrivateKey, config *Config, msg []byte) ([]byte, error) {
	rsaKey, ok := key.(*rsa.PrivateKey)
	if !ok {
		return nil, errors.New("invalid key type for RSA-PSS")
	}

	h := r.hash.New()
	h.Write(msg)
	return rsa.SignPSS(config.rand(), rsaKey, r.hash, h.Sum(nil), &pssOptions)
}
开发者ID:onedata,项目名称:helpers,代码行数:10,代码来源:sign.go

示例9: Sign

// Sign uses the private key to sign provided string and returns the result as a base64.URLEncoded string
func (m *Manager) Sign(s string) (string, error) {
	h := sha256.New()
	h.Write([]byte(s))
	d := h.Sum(nil)
	sig, err := rsa.SignPSS(rand.Reader, m.PrivateKey, crypto.SHA256, d, nil)
	if err != nil {
		return "", err
	}

	return base64.URLEncoding.EncodeToString(sig), nil
}
开发者ID:sethjback,项目名称:gobl,代码行数:12,代码来源:manager.go

示例10: Sign

// Sign implements the Sign method from SigningMethod.
// For this signing method, key must be an *rsa.PrivateKey.
func (m *SigningMethodRSAPSS) Sign(raw []byte, key interface{}) (Signature, error) {
	rsaKey, ok := key.(*rsa.PrivateKey)
	if !ok {
		return nil, ErrInvalidKey
	}
	sigBytes, err := rsa.SignPSS(rand.Reader, rsaKey, m.Hash, m.sum(raw), m.Options)
	if err != nil {
		return nil, err
	}
	return Signature(sigBytes), nil
}
开发者ID:andrefreitas,项目名称:jose,代码行数:13,代码来源:rsa_pss.go

示例11: GenerateMessageSignature

func GenerateMessageSignature(senderPrivKey *rsa.PrivateKey, plainText []byte) ([]byte, error) {
	pssh := newhash.New()
	_, err := pssh.Write(plainText)
	if err != nil {
		return nil, err
	}

	hashed := pssh.Sum(nil)
	signature, err := rsa.SignPSS(rand.Reader, senderPrivKey, newhash, hashed, opts)
	return signature, err
}
开发者ID:golang-devops,项目名称:go-psexec,代码行数:11,代码来源:encryption_asymmetric.go

示例12: Encrypt

// Encrypt signs the message with the private key, and encrypts it to
// the certificate supplied.
func Encrypt(priv *rsa.PrivateKey, cert *x509.Certificate, msg []byte) ([]byte, bool) {
	var pub *rsa.PublicKey
	switch certPub := cert.PublicKey.(type) {
	case *rsa.PublicKey:
		pub = certPub
	default:
		return nil, false
	}

	var signed = signature{msg, nil}

	h := sha256.New()
	h.Write(msg)

	var err error
	signed.Signature, err = rsa.SignPSS(rand.Reader, priv, crypto.SHA256,
		h.Sum(nil), nil)
	if err != nil {
		return nil, false
	}

	out, err := asn1.Marshal(signed)
	if err != nil {
		return nil, false
	}

	key := aesgcm.NewKey()
	if key == nil {
		return nil, false
	}

	out, ok := aesgcm.Encrypt(key, out)
	if !ok {
		return nil, false
	}

	var message message
	message.Signed = out

	h.Reset()
	message.Key, err = rsa.EncryptOAEP(h, rand.Reader, pub, key, nil)
	if err != nil {
		return nil, false
	}

	out, err = asn1.Marshal(message)
	if err != nil {
		return nil, false
	}

	return out, true
}
开发者ID:kisom,项目名称:tlscrypt,代码行数:54,代码来源:tlscrypt.go

示例13: main

func main() {
	priv, err := rsa.GenerateKey(rand.Reader, 2048)
	checkFatal(err)

	message := []byte("Binding contractual agreement...")

	h := sha256.New()
	h.Write(message)
	digest := h.Sum(nil)
	sig, err := rsa.SignPSS(rand.Reader, priv, crypto.SHA256, digest, nil)
	checkFatal(err)

	fmt.Printf("Signature: %x\n", sig)
	err = rsa.VerifyPSS(&priv.PublicKey, crypto.SHA256, digest, sig, nil)
	fmt.Printf("Signature OK: %v\n", err == nil)
}
开发者ID:kisom,项目名称:gosf201407,代码行数:16,代码来源:rsasign.go

示例14: rsaPSSSign

func rsaPSSSign(privKey data.PrivateKey, hash crypto.Hash, hashed []byte) ([]byte, error) {
	if privKey, ok := privKey.(*data.RSAPrivateKey); !ok {
		return nil, fmt.Errorf("private key type not supported: %s", privKey.Algorithm())
	}

	// Create an rsa.PrivateKey out of the private key bytes
	rsaPrivKey, err := x509.ParsePKCS1PrivateKey(privKey.Private())
	if err != nil {
		return nil, err
	}

	// Use the RSA key to RSASSA-PSS sign the data
	sig, err := rsa.SignPSS(rand.Reader, rsaPrivKey, hash, hashed[:], &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash})
	if err != nil {
		return nil, err
	}

	return sig, nil
}
开发者ID:useidel,项目名称:notary,代码行数:19,代码来源:verifiers_test.go

示例15: signPayload

// Sign the given payload
func (ctx rsaDecrypterSigner) signPayload(payload []byte, alg SignatureAlgorithm) (Signature, error) {
	var hash crypto.Hash

	switch alg {
	case RS256, PS256:
		hash = crypto.SHA256
	case RS384, PS384:
		hash = crypto.SHA384
	case RS512, PS512:
		hash = crypto.SHA512
	default:
		return Signature{}, ErrUnsupportedAlgorithm
	}

	hasher := hash.New()

	// According to documentation, Write() on hash never fails
	_, _ = hasher.Write(payload)
	hashed := hasher.Sum(nil)

	var out []byte
	var err error

	switch alg {
	case RS256, RS384, RS512:
		out, err = rsa.SignPKCS1v15(randReader, ctx.privateKey, hash, hashed)
	case PS256, PS384, PS512:
		out, err = rsa.SignPSS(randReader, ctx.privateKey, hash, hashed, &rsa.PSSOptions{
			SaltLength: rsa.PSSSaltLengthAuto,
		})
	}

	if err != nil {
		return Signature{}, err
	}

	return Signature{
		Signature: out,
		protected: &rawHeader{},
	}, nil
}
开发者ID:ossrs,项目名称:go-oryx-lib,代码行数:42,代码来源:asymmetric.go


注:本文中的crypto/rsa.SignPSS函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。