Package com.mku.salmon.transform
Interface ISalmonCTRTransformer
- All Known Implementing Classes:
SalmonAES256CTRTransformer
,SalmonAesIntrTransformer
,SalmonDefaultTransformer
,SalmonNativeTransformer
,TinyAesTransformer
public interface ISalmonCTRTransformer
Contract for the encryption/decryption transformers.
Note that Counter mode needs to be supported.
-
Method Summary
Modifier and TypeMethodDescriptionint
decryptData
(byte[] srcBuffer, int srcOffset, byte[] destBuffer, int destOffset, int count) Decrypt the data.int
encryptData
(byte[] srcBuffer, int srcOffset, byte[] destBuffer, int destOffset, int count) Encrypt the data.long
getBlock()
Get the current block.byte[]
Get the current counter.byte[]
getKey()
Get the current encryption key.byte[]
getNonce()
Get the nonce (initial counter) to be used for the data.void
init
(byte[] key, byte[] nonce) Initialize the transformer.void
Reset the counter to the nonce (initial counter).void
syncCounter
(long position) Calculate the value of the counter based on the current block.
-
Method Details
-
init
void init(byte[] key, byte[] nonce) Initialize the transformer.- Parameters:
key
- The AES key to use.nonce
- The nonce to use.- Throws:
SalmonSecurityException
- Thrown if there is a security exception
-
encryptData
int encryptData(byte[] srcBuffer, int srcOffset, byte[] destBuffer, int destOffset, int count) Encrypt the data.- Parameters:
srcBuffer
- The source byte array.srcOffset
- The source byte offset.destBuffer
- The destination byte array.destOffset
- The destination byte offset.count
- The number of bytes to transform.- Returns:
- The number of bytes transformed.
- Throws:
SalmonSecurityException
- Thrown if there is a security exceptionSalmonRangeExceededException
- Thrown if the nonce exceeds its range
-
decryptData
int decryptData(byte[] srcBuffer, int srcOffset, byte[] destBuffer, int destOffset, int count) Decrypt the data.- Parameters:
srcBuffer
- The source byte array.srcOffset
- The source byte offset.destBuffer
- The destination byte array.destOffset
- The destination byte offset.count
- The number of bytes to transform.- Returns:
- The number of bytes transformed.
- Throws:
SalmonSecurityException
- Thrown if there is a security exceptionSalmonRangeExceededException
- Thrown if the nonce exceeds its range
-
getCounter
byte[] getCounter()Get the current counter.- Returns:
- The counter
-
getKey
byte[] getKey()Get the current encryption key.- Returns:
- The key
-
getBlock
long getBlock()Get the current block.- Returns:
- The block
-
getNonce
byte[] getNonce()Get the nonce (initial counter) to be used for the data.- Returns:
- The nonce
-
resetCounter
void resetCounter()Reset the counter to the nonce (initial counter). -
syncCounter
void syncCounter(long position) Calculate the value of the counter based on the current block. After an encryption operation (ie sync or read) the block will be incremented. This method calculates the Counter.- Parameters:
position
- The position to sync the counter to- Throws:
SalmonRangeExceededException
- Thrown if the nonce exceeds its range
-