Package dev.dsf.bpe.v2.service
Interface CryptoService.Kem
- Enclosing interface:
CryptoService
public static interface CryptoService.Kem
Key encapsulation mechanism with encrypt and decrypt methods.
-
Method Summary
Modifier and TypeMethodDescriptiondefault byte[]
decrypt
(byte[] encrypted, PrivateKey privateKey) decrypt
(InputStream encrypted, PrivateKey privateKey) default byte[]
Encrypts the givenInputStream
with an AES session key calculated by KEM for the givenPublicKey
.encrypt
(InputStream data, PublicKey publicKey) Encrypts the givenInputStream
with an AES session key calculated by KEM for the givenPublicKey
.
-
Method Details
-
encrypt
default byte[] encrypt(byte[] data, PublicKey publicKey) throws IOException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, InvalidAlgorithmParameterException Encrypts the givenInputStream
with an AES session key calculated by KEM for the givenPublicKey
. The returnedInputStream
has the form [encapsulation length (big-endian, 2 bytes), encapsulation, AES initialization vector (12 bytes), AES encrypted data].- Parameters:
data
- notnull
publicKey
- notnull
- Returns:
- byte array of [encapsulation length (big-endian, 2 bytes), encapsulation, iv (12 bytes), encrypted data]
- Throws:
IOException
NoSuchAlgorithmException
InvalidKeyException
NoSuchPaddingException
InvalidAlgorithmParameterException
-
encrypt
InputStream encrypt(InputStream data, PublicKey publicKey) throws IOException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, InvalidAlgorithmParameterException Encrypts the givenInputStream
with an AES session key calculated by KEM for the givenPublicKey
. The returnedInputStream
has the form [encapsulation length (big-endian, 2 bytes), encapsulation, AES initialization vector (12 bytes), AES encrypted data].- Parameters:
data
- notnull
publicKey
- notnull
- Returns:
InputStream
of [encapsulation length (big-endian, 2 bytes), encapsulation, iv (12 bytes), encrypted data]- Throws:
IOException
NoSuchAlgorithmException
InvalidKeyException
NoSuchPaddingException
InvalidAlgorithmParameterException
-
decrypt
default byte[] decrypt(byte[] encrypted, PrivateKey privateKey) throws IOException, NoSuchAlgorithmException, InvalidKeyException, DecapsulateException, NoSuchPaddingException, InvalidAlgorithmParameterException - Parameters:
encrypted
- notnull
,InputStream
of [encapsulation length (big-endian, 2 bytes), encapsulation, iv (12 bytes), encrypted data]privateKey
- notnull
- Returns:
- decrypted data
- Throws:
IOException
NoSuchAlgorithmException
InvalidKeyException
DecapsulateException
NoSuchPaddingException
InvalidAlgorithmParameterException
-
decrypt
InputStream decrypt(InputStream encrypted, PrivateKey privateKey) throws IOException, NoSuchAlgorithmException, InvalidKeyException, DecapsulateException, NoSuchPaddingException, InvalidAlgorithmParameterException - Parameters:
encrypted
- notnull
,InputStream
of [encapsulation length (big-endian, 2 bytes), encapsulation, iv (12 bytes), encrypted data]privateKey
- notnull
- Returns:
- decrypted data
- Throws:
IOException
NoSuchAlgorithmException
InvalidKeyException
DecapsulateException
NoSuchPaddingException
InvalidAlgorithmParameterException
-