Sha256: 2529c5b93490f81c7c820f33fa480e7e7573fb8532f6d18a97fd30d0c239f5e5

Contents?: true

Size: 1.09 KB

Versions: 16

Compression:

Stored size: 1.09 KB

Contents

package jose

import (
	"errors"
	"crypto/rsa"
	"crypto/rand"
	"github.com/dvsekhvalnov/jose2go/arrays"
)

func init() {
	RegisterJwa(new(RsaPkcs1v15))
}

// RS-AES using PKCS #1 v1.5 padding key management algorithm implementation
type RsaPkcs1v15 struct{
}

func (alg *RsaPkcs1v15) Name() string {
	return RSA1_5
}

func (alg *RsaPkcs1v15) WrapNewKey(cekSizeBits int, key interface{}, header map[string]interface{}) (cek []byte, encryptedCek []byte, err error) {
	if pubKey,ok:=key.(*rsa.PublicKey);ok {		
		if cek,err = arrays.Random(cekSizeBits>>3);err==nil {			
			encryptedCek,err=rsa.EncryptPKCS1v15(rand.Reader,pubKey,cek)			
			return
		}
		
		return nil,nil,err
	}
	
	return nil,nil,errors.New("RsaPkcs1v15.WrapNewKey(): expected key to be '*rsa.PublicKey'")		
}

func (alg *RsaPkcs1v15) Unwrap(encryptedCek []byte, key interface{}, cekSizeBits int, header map[string]interface{}) (cek []byte, err error) {
	if privKey,ok:=key.(*rsa.PrivateKey);ok {
		return rsa.DecryptPKCS1v15(rand.Reader,privKey,encryptedCek)
	}
	
	return nil,errors.New("RsaPkcs1v15.Unwrap(): expected key to be '*rsa.PrivateKey'")		
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_snowflake_client-1.3.7 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.3.6 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.3.5 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.3.4 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.3.4.pre.debug ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.3.3.pre.debug ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.3.2 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.3.1 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.3.0 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.2.1 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.2.0 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.1.1 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.1.0 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.0.2 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.0.1 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go
ruby_snowflake_client-1.0.0 ext/vendor/github.com/dvsekhvalnov/jose2go/rsa_pkcs1v15.go