...

Source file src/github.com/lestrrat-go/jwx/jwe/internal/keyenc/interface.go

Documentation: github.com/lestrrat-go/jwx/jwe/internal/keyenc

     1  package keyenc
     2  
     3  import (
     4  	"crypto/rsa"
     5  	"hash"
     6  
     7  	"github.com/lestrrat-go/jwx/jwa"
     8  	"github.com/lestrrat-go/jwx/jwe/internal/keygen"
     9  )
    10  
    11  // Encrypter is an interface for things that can encrypt keys
    12  type Encrypter interface {
    13  	Algorithm() jwa.KeyEncryptionAlgorithm
    14  	Encrypt([]byte) (keygen.ByteSource, error)
    15  	// KeyID returns the key id for this Encrypter. This exists so that
    16  	// you can pass in a Encrypter to MultiEncrypt, you can rest assured
    17  	// that the generated key will have the proper key ID.
    18  	KeyID() string
    19  
    20  	SetKeyID(string)
    21  }
    22  
    23  // Decrypter is an interface for things that can decrypt keys
    24  type Decrypter interface {
    25  	Algorithm() jwa.KeyEncryptionAlgorithm
    26  	Decrypt([]byte) ([]byte, error)
    27  }
    28  
    29  type Noop struct {
    30  	alg       jwa.KeyEncryptionAlgorithm
    31  	keyID     string
    32  	sharedkey []byte
    33  }
    34  
    35  // AES encrypts content encryption keys using AES key wrap.
    36  // Contrary to what the name implies, it also decrypt encrypted keys
    37  type AES struct {
    38  	alg       jwa.KeyEncryptionAlgorithm
    39  	keyID     string
    40  	sharedkey []byte
    41  }
    42  
    43  // AESGCM encrypts content encryption keys using AES-GCM key wrap.
    44  type AESGCMEncrypt struct {
    45  	algorithm jwa.KeyEncryptionAlgorithm
    46  	keyID     string
    47  	sharedkey []byte
    48  }
    49  
    50  // ECDHESEncrypt encrypts content encryption keys using ECDH-ES.
    51  type ECDHESEncrypt struct {
    52  	algorithm jwa.KeyEncryptionAlgorithm
    53  	keyID     string
    54  	generator keygen.Generator
    55  }
    56  
    57  // ECDHESDecrypt decrypts keys using ECDH-ES.
    58  type ECDHESDecrypt struct {
    59  	keyalg     jwa.KeyEncryptionAlgorithm
    60  	contentalg jwa.ContentEncryptionAlgorithm
    61  	apu        []byte
    62  	apv        []byte
    63  	privkey    interface{}
    64  	pubkey     interface{}
    65  }
    66  
    67  // RSAOAEPEncrypt encrypts keys using RSA OAEP algorithm
    68  type RSAOAEPEncrypt struct {
    69  	alg    jwa.KeyEncryptionAlgorithm
    70  	pubkey *rsa.PublicKey
    71  	keyID  string
    72  }
    73  
    74  // RSAOAEPDecrypt decrypts keys using RSA OAEP algorithm
    75  type RSAOAEPDecrypt struct {
    76  	alg     jwa.KeyEncryptionAlgorithm
    77  	privkey *rsa.PrivateKey
    78  }
    79  
    80  // RSAPKCS15Decrypt decrypts keys using RSA PKCS1v15 algorithm
    81  type RSAPKCS15Decrypt struct {
    82  	alg       jwa.KeyEncryptionAlgorithm
    83  	privkey   *rsa.PrivateKey
    84  	generator keygen.Generator
    85  }
    86  
    87  // RSAPKCSEncrypt encrypts keys using RSA PKCS1v15 algorithm
    88  type RSAPKCSEncrypt struct {
    89  	alg    jwa.KeyEncryptionAlgorithm
    90  	pubkey *rsa.PublicKey
    91  	keyID  string
    92  }
    93  
    94  // DirectDecrypt does no encryption (Note: Unimplemented)
    95  type DirectDecrypt struct {
    96  	Key []byte
    97  }
    98  
    99  // PBES2Encrypt encrypts keys with PBES2 / PBKDF2 password
   100  type PBES2Encrypt struct {
   101  	algorithm jwa.KeyEncryptionAlgorithm
   102  	hashFunc  func() hash.Hash
   103  	keylen    int
   104  	keyID     string
   105  	password  []byte
   106  }
   107  

View as plain text