github.com/lestrrat-go/jwx/v2@v2.0.21/jwe/internal/keyenc/interface.go (about)

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