本文整理汇总了Golang中crypto/rsa.SignPSS函数的典型用法代码示例。如果您正苦于以下问题:Golang SignPSS函数的具体用法?Golang SignPSS怎么用?Golang SignPSS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SignPSS函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: rsaSign
func rsaSign(privKey data.PrivateKey, message []byte) ([]byte, error) {
if privKey.Algorithm() != data.RSAKey {
return nil, fmt.Errorf("private key type not supported: %s", privKey.Algorithm())
}
hashed := sha256.Sum256(message)
// 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, crypto.SHA256, hashed[:], &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash})
if err != nil {
return nil, err
}
return sig, nil
}
开发者ID:souravbh,项目名称:lattice-release,代码行数:21,代码来源:crypto_service.go
示例17: NewMsg
func NewMsg(from, to string, fromkey *rsa.PrivateKey, tokey *rsa.PublicKey, data []byte) (*Msg, error) {
hash := crypto.SHA256
max := tokey.N.BitLen()/8 - 2*hash.Size() - 2
num := len(data) / max
if len(data)%max > 0 {
num++
}
msg := &Msg{
From: from,
To: to,
Data: make([][]byte, num),
Signature: make([][]byte, num),
}
j := 0
for i := 0; i < len(data); i += max {
end := i + max
if end > len(data) {
end = len(data)
}
ciphertex, err := rsa.EncryptOAEP(hash.New(), rand.Reader, tokey, data[i:end], []byte(""))
if err != nil {
return nil, e.Push(err, "can't encrypt message")
}
pssh := hash.New()
pssh.Write(data[i:end])
hashed := pssh.Sum(nil)
var opts rsa.PSSOptions
opts.SaltLength = rsa.PSSSaltLengthAuto
signature, err := rsa.SignPSS(rand.Reader, fromkey, hash, hashed, &opts)
if err != nil {
return nil, e.Push(err, "can't sign the message")
}
msg.Data[j] = ciphertex
msg.Signature[j] = signature
j++
}
return msg, nil
}
开发者ID:fcavani,项目名称:discover,代码行数:40,代码来源:message.go
示例18: SignMessage
func SignMessage(pmsg PeerMessage) PeerMessage {
pmsg_bytes, err := json.Marshal(pmsg)
if err != nil {
log.Fatal("(SignMessage) JSON Error: ", err)
}
newhash := crypto.SHA1
pssh := newhash.New()
pssh.Write(pmsg_bytes)
hashed := pssh.Sum(nil)
signaturePSS, err := rsa.SignPSS(rand.Reader, pvkey, newhash, hashed, nil)
if err != nil {
log.Fatal(err)
}
pmsg.Hashed = hashed
pmsg.Sig = signaturePSS
return pmsg
}
开发者ID:imgemp,项目名称:WeTube,代码行数:22,代码来源:WeTubeClient.go
示例19: Sign
//Sign creates the signature for a message
func (rsaKey *RsaKey) Sign(message string) (signature string, err error) {
var signatureBytes []byte
hashAlgorithm := crypto.SHA256
messageBytes := bytes.NewBufferString(message)
//hash
hasher := hashAlgorithm.New()
hasher.Write(messageBytes.Bytes())
messageHash := hasher.Sum(nil)
//sign
var pssOptions rsa.PSSOptions
pssOptions.SaltLength = saltSize
pssOptions.Hash = hashAlgorithm
signatureBytes, err = rsa.SignPSS(rand.Reader, rsaKey.privateKey, hashAlgorithm, messageHash, &pssOptions)
if err != nil {
return
}
signature = base64.StdEncoding.EncodeToString(signatureBytes)
return
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:24,代码来源:rsa_key.go
示例20: SignBytes
func SignBytes(data []byte, priv *rsa.PrivateKey) (s []byte, err error) {
hash := sha256.Sum256(data)
return rsa.SignPSS(rand.Reader, priv, crypto.SHA256, hash[:], &rsa.PSSOptions{})
}
开发者ID:carriercomm,项目名称:tarsnap-server,代码行数:5,代码来源:rsa.go
注:本文中的crypto/rsa.SignPSS函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论