Package com.github.ambry.router
Class GCMCryptoService
- java.lang.Object
-
- com.github.ambry.router.GCMCryptoService
-
- All Implemented Interfaces:
com.github.ambry.router.CryptoService<javax.crypto.spec.SecretKeySpec>
public class GCMCryptoService extends java.lang.Object implements com.github.ambry.router.CryptoService<javax.crypto.spec.SecretKeySpec>
CryptoService
which is capable of encrypting or decrypting bytes based on the given key. This implementation uses GCM for encryption and decryption
-
-
Constructor Summary
Constructors Constructor Description GCMCryptoService(com.github.ambry.config.CryptoServiceConfig cryptoServiceConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.netty.buffer.ByteBuf
decrypt(io.netty.buffer.ByteBuf toDecrypt, javax.crypto.spec.SecretKeySpec key)
java.nio.ByteBuffer
decrypt(java.nio.ByteBuffer toDecrypt, javax.crypto.spec.SecretKeySpec key)
javax.crypto.spec.SecretKeySpec
decryptKey(java.nio.ByteBuffer toDecrypt, javax.crypto.spec.SecretKeySpec key)
io.netty.buffer.ByteBuf
encrypt(io.netty.buffer.ByteBuf toEncrypt, javax.crypto.spec.SecretKeySpec key)
io.netty.buffer.ByteBuf
encrypt(io.netty.buffer.ByteBuf toEncrypt, javax.crypto.spec.SecretKeySpec key, byte[] iv)
Helper function to encrypt ByteBuf with the given key.java.nio.ByteBuffer
encrypt(java.nio.ByteBuffer toEncrypt, javax.crypto.spec.SecretKeySpec key)
java.nio.ByteBuffer
encryptKey(javax.crypto.spec.SecretKeySpec toEncrypt, javax.crypto.spec.SecretKeySpec key)
-
-
-
Method Detail
-
encrypt
public java.nio.ByteBuffer encrypt(java.nio.ByteBuffer toEncrypt, javax.crypto.spec.SecretKeySpec key) throws java.security.GeneralSecurityException
- Specified by:
encrypt
in interfacecom.github.ambry.router.CryptoService<javax.crypto.spec.SecretKeySpec>
- Throws:
java.security.GeneralSecurityException
-
encrypt
public io.netty.buffer.ByteBuf encrypt(io.netty.buffer.ByteBuf toEncrypt, javax.crypto.spec.SecretKeySpec key) throws java.security.GeneralSecurityException
- Specified by:
encrypt
in interfacecom.github.ambry.router.CryptoService<javax.crypto.spec.SecretKeySpec>
- Throws:
java.security.GeneralSecurityException
-
encrypt
public io.netty.buffer.ByteBuf encrypt(io.netty.buffer.ByteBuf toEncrypt, javax.crypto.spec.SecretKeySpec key, byte[] iv) throws java.security.GeneralSecurityException
Helper function to encrypt ByteBuf with the given key. When useFixedIv is true, don't use a random iv byte array, using a all zero byte array instead. Only set it to be true in test.- Parameters:
toEncrypt
-ByteBuf
that needs to be encryptedkey
- the secret key (of type T) to use to encryptiv
- If null, will create a random byte array serve as iv bytes.- Returns:
- the
ByteBuf
containing the encrypted content. Ensure the result has all the information like the IV along with the encrypted content, in order to decrypt the content with a given key - Throws:
java.security.GeneralSecurityException
-
decrypt
public java.nio.ByteBuffer decrypt(java.nio.ByteBuffer toDecrypt, javax.crypto.spec.SecretKeySpec key) throws java.security.GeneralSecurityException
- Specified by:
decrypt
in interfacecom.github.ambry.router.CryptoService<javax.crypto.spec.SecretKeySpec>
- Throws:
java.security.GeneralSecurityException
-
decrypt
public io.netty.buffer.ByteBuf decrypt(io.netty.buffer.ByteBuf toDecrypt, javax.crypto.spec.SecretKeySpec key) throws java.security.GeneralSecurityException
- Specified by:
decrypt
in interfacecom.github.ambry.router.CryptoService<javax.crypto.spec.SecretKeySpec>
- Throws:
java.security.GeneralSecurityException
-
encryptKey
public java.nio.ByteBuffer encryptKey(javax.crypto.spec.SecretKeySpec toEncrypt, javax.crypto.spec.SecretKeySpec key) throws java.security.GeneralSecurityException
- Specified by:
encryptKey
in interfacecom.github.ambry.router.CryptoService<javax.crypto.spec.SecretKeySpec>
- Throws:
java.security.GeneralSecurityException
-
decryptKey
public javax.crypto.spec.SecretKeySpec decryptKey(java.nio.ByteBuffer toDecrypt, javax.crypto.spec.SecretKeySpec key) throws java.security.GeneralSecurityException
- Specified by:
decryptKey
in interfacecom.github.ambry.router.CryptoService<javax.crypto.spec.SecretKeySpec>
- Throws:
java.security.GeneralSecurityException
-
-