Class Cipher.OneShot
- Enclosing class:
Cipher
OneShot class is a specialization of the Cipher
class intended to support efficient one-shot ciphering and deciphering
operations that may avoid persistent memory writes entirely. The
OneShot class uses a delegation model where calls are delegated
to an instance of a Cipher-implementing class configured for
one-shot use.
Note:
- Instances of
OneShotare JCRE owned temporary Entry Point Object instances and references to these temporary objects cannot be stored in class variables or instance variables or array components. See Runtime Environment Specification, Java Card Platform, Classic Edition, section 6.2.1 for details. - The platform must support at least one instance of
OneShot. Support for severalOneShotinstances is platform dependent. To guarantee application code portability, acquiring/opening and then releasing/closingOneShotinstances should be performed within tighttry-catch-finallyblocks (as illustrated in the code sample below) in order to avoid unnecessarily keeping hold of instances and to prevent interleaving invocations - hence enforcing the One-Shot usage pattern. Additionally, any local variable holding a reference to aOneShotinstance should be set tonullonce the instance is closed in order to prevent further use attempts. - Upon return from any
Appletentry point method, back to the JCRE, and on tear or card reset events anyOneShotinstances in use are released back to the JCRE. - The internal state associated with an instance of
OneShotmust be bound to the initial calling context (owner context) as to preclude use/calls on that instance from other contexts. - Unless otherwise specified, after an instance of
OneShotis released back to the JCRE, calls to any of the instance methods of theOneShotclass results in anCryptoExceptionbeing thrown with reason codeCryptoException.ILLEGAL_USE.
The following code shows a typical usage pattern for the
OneShot class.
...
Cipher.OneShot enc = null;
try {
enc = Cipher.OneShot.open(Cipher.CIPHER_RSA, Cipher.PAD_PKCS1);
enc.init(someRSAKey, Cipher.MODE_ENCRYPT);
enc.doFinal(someInData, (short) 0, (short) someInData.length, encData, (short) 0);
} catch (CryptoException ce) {
// Handle exception
} finally {
if (enc != null) {
enc.close();
enc = null;
}
}
...
- Since:
- 3.0.5
-
Nested Class Summary
Nested classes/interfaces inherited from class Cipher
Cipher.OneShotModifier and TypeClassDescriptionstatic final classTheOneShotclass is a specialization of theCipherclass intended to support efficient one-shot ciphering and deciphering operations that may avoid persistent memory writes entirely. -
Field Summary
Fields inherited from class Cipher
ALG_AES_BLOCK_128_CBC_NOPAD, ALG_AES_BLOCK_128_ECB_NOPAD, ALG_AES_BLOCK_192_CBC_NOPAD, ALG_AES_BLOCK_192_ECB_NOPAD, ALG_AES_BLOCK_256_CBC_NOPAD, ALG_AES_BLOCK_256_ECB_NOPAD, ALG_AES_CBC_ISO9797_M1, ALG_AES_CBC_ISO9797_M2, ALG_AES_CBC_PKCS5, ALG_AES_CFB, ALG_AES_CTR, ALG_AES_ECB_ISO9797_M1, ALG_AES_ECB_ISO9797_M2, ALG_AES_ECB_PKCS5, ALG_AES_XTS, ALG_DES_CBC_ISO9797_M1, ALG_DES_CBC_ISO9797_M2, ALG_DES_CBC_NOPAD, ALG_DES_CBC_PKCS5, ALG_DES_ECB_ISO9797_M1, ALG_DES_ECB_ISO9797_M2, ALG_DES_ECB_NOPAD, ALG_DES_ECB_PKCS5, ALG_KOREAN_SEED_CBC_NOPAD, ALG_KOREAN_SEED_ECB_NOPAD, ALG_RSA_ISO14888, ALG_RSA_ISO9796, ALG_RSA_NOPAD, ALG_RSA_PKCS1, ALG_RSA_PKCS1_OAEP, CIPHER_AES_CBC, CIPHER_AES_CFB, CIPHER_AES_CTR, CIPHER_AES_ECB, CIPHER_AES_XTS, CIPHER_DES_CBC, CIPHER_DES_ECB, CIPHER_KOREAN_SEED_CBC, CIPHER_KOREAN_SEED_ECB, CIPHER_RSA, CIPHER_SM2, CIPHER_SM4_CBC, CIPHER_SM4_ECB, MODE_DECRYPT, MODE_ENCRYPT, PAD_ISO9796, PAD_ISO9796_MR, PAD_ISO9796_MR_SCHEME_1_OPT_2, PAD_ISO9796_MR_SCHEME_2, PAD_ISO9796_MR_SCHEME_2_OPT_2, PAD_ISO9796_MR_SCHEME_3, PAD_ISO9796_MR_SCHEME_3_OPT_2, PAD_ISO9797_1_M1_ALG3, PAD_ISO9797_1_M2_ALG3, PAD_ISO9797_M1, PAD_ISO9797_M2, PAD_NOPAD, PAD_NULL, PAD_PKCS1, PAD_PKCS1_OAEP, PAD_PKCS1_OAEP_EXT_PARAMETERS, PAD_PKCS1_OAEP_SHA224, PAD_PKCS1_OAEP_SHA256, PAD_PKCS1_OAEP_SHA3_224, PAD_PKCS1_OAEP_SHA3_256, PAD_PKCS1_OAEP_SHA3_384, PAD_PKCS1_OAEP_SHA3_512, PAD_PKCS1_OAEP_SHA384, PAD_PKCS1_OAEP_SHA512, PAD_PKCS1_PSS, PAD_PKCS1_PSS_EXT_PARAMETERS, PAD_PKCS5, PAD_RFC2409Modifier and TypeFieldDescriptionstatic final byteCipher algorithmALG_AES_BLOCK_128_CBC_NOPADprovides a cipher using AES with block size 128 in CBC mode and does not pad input data.static final byteCipher algorithmALG_AES_BLOCK_128_ECB_NOPADprovides a cipher using AES with block size 128 in ECB mode and does not pad input data.static final byteDeprecated.static final byteDeprecated.static final byteDeprecated.static final byteDeprecated.static final byteCipher algorithmALG_AES_CBC_ISO9797_M1provides a cipher using AES with block size 128 in CBC mode, and pads input data according to the ISO 9797 method 1 scheme.static final byteCipher algorithmALG_AES_CBC_ISO9797_M2provides a cipher using AES with block size 128 in CBC mode, and pads input data according to the ISO 9797 method 2 (ISO 7816-4, EMV'96) scheme.static final byteCipher algorithmALG_AES_CBC_PKCS5provides a cipher using AES with block size 128 in CBC mode, and pads input data according to the PKCS#5 scheme.static final byteCipher AlgorithmALG_AES_CFBprovides a cipher using AES in Cipher Feedback (CFB) mode.static final byteCipher algorithmALG_AES_CTRprovides a cipher using AES in counter (CTR) mode.static final byteCipher algorithmALG_AES_ECB_ISO9797_M1provides a cipher using AES with block size 128 in ECB mode, and pads input data according to the ISO 9797 method 1 scheme.static final byteCipher algorithmALG_AES_ECB_ISO9797_M2provides a cipher using AES with block size 128 in ECB mode, and pads input data according to the ISO 9797 method 2 (ISO 7816-4, EMV'96) scheme.static final byteCipher algorithmALG_AES_ECB_PKCS5provides a cipher using AES with block size 128 in ECB mode, and pads input data according to the PKCS#5 scheme.static final byteCipher AlgorithmALG_AES_XTSprovides a cipher using AES in XEX Tweakable Block Cipher with Ciphertext Stealing (XTS) mode as defined in IEEE Std 1619.static final byteCipher algorithmALG_DES_CBC_ISO9797_M1provides a cipher using DES in CBC mode or triple DES in outer CBC mode, and pads input data according to the ISO 9797 method 1 scheme.static final byteCipher algorithmALG_DES_CBC_ISO9797_M2provides a cipher using DES in CBC mode or triple DES in outer CBC mode, and pads input data according to the ISO 9797 method 2 (ISO 7816-4, EMV'96) scheme.static final byteCipher algorithmALG_DES_CBC_NOPADprovides a cipher using DES in CBC mode or triple DES in outer CBC mode, and does not pad input data.static final byteCipher algorithmALG_DES_CBC_PKCS5provides a cipher using DES in CBC mode or triple DES in outer CBC mode, and pads input data according to the PKCS#5 scheme.static final byteCipher algorithmALG_DES_ECB_ISO9797_M1provides a cipher using DES in ECB mode, and pads input data according to the ISO 9797 method 1 scheme.static final byteCipher algorithmALG_DES_ECB_ISO9797_M2provides a cipher using DES in ECB mode, and pads input data according to the ISO 9797 method 2 (ISO 7816-4, EMV'96) scheme.static final byteCipher algorithmALG_DES_ECB_NOPADprovides a cipher using DES in ECB mode, and does not pad input data.static final byteCipher algorithmALG_DES_ECB_PKCS5provides a cipher using DES in ECB mode, and pads input data according to the PKCS#5 scheme.static final byteCipher algorithmALG_KOREAN_SEED_CBC_NOPADprovides a cipher using the Korean SEED algorithm specified in the Korean SEED Algorithm specification provided by KISA, Korea Information Security Agency in CBC mode and does not pad input data.static final byteCipher algorithmALG_KOREAN_SEED_ECB_NOPADprovides a cipher using the Korean SEED algorithm specified in the Korean SEED Algorithm specification provided by KISA, Korea Information Security Agency in ECB mode and does not pad input data.static final byteDeprecated.static final byteDeprecated.static final byteCipher algorithmALG_RSA_NOPADprovides a cipher using RSA and does not pad input data.static final byteCipher algorithmALG_RSA_PKCS1provides a cipher using RSA, and pads input data according to the PKCS#1 (v1.5) scheme.static final byteCipher algorithmALG_RSA_PKCS1_OAEPprovides a cipher using RSA, and pads input data according to the PKCS#1-OAEP scheme (IEEE 1363-2000) with SHA-1 as default message digest algorithm for both the scheme and MGF1.static final byteCipher algorithmCIPHER_AES_CBCchoice for thecipherAlgorithmparameter of thegetInstance(byte, byte, boolean)method.static final byteTheCIPHER_AES_CFBconstant represents a cipher using AES in Cipher Feedback (CFB) mode.static final byteTheCIPHER_AES_CTRconstant represents a cipher using AES in counter (CTR) mode.static final byteCipher algorithmCIPHER_AES_ECBchoice for thecipherAlgorithmparameter of thegetInstance(byte, byte, boolean)method.static final byteTheCIPHER_AES_XTSconstant represents a cipher using AES in XEX Tweakable Block Cipher with Ciphertext Stealing (XTS) mode as defined in IEEE Std 1619.static final byteCipher algorithmCIPHER_DES_CBCchoice for thecipherAlgorithmparameter of thegetInstance(byte, byte, boolean)method.static final byteCipher algorithmCIPHER_DES_ECBchoice for thecipherAlgorithmparameter of thegetInstance(byte, byte, boolean)method.static final byteCipher algorithmCIPHER_KOREAN_SEED_CBCchoice for thecipherAlgorithmparameter of thegetInstance(byte, byte, boolean)method.static final byteCipher algorithmCIPHER_KOREAN_SEED_ECBchoice for thecipherAlgorithmparameter of thegetInstance(byte, byte, boolean)method.static final byteCipher algorithmCIPHER_RSAchoice for thecipherAlgorithmparameter of thegetInstance(byte, byte, boolean)method.static final byteTheCIPHER_SM2constant represents a cipher using SM2 encryption as defined in GM/T 0003.4-2012 (Public Key Cryptographic Algorithm SM2 Based on Elliptic Curves Part 4: Public Key Encryption Algorithm).static final byteTheCIPHER_SM4_CBCconstant represents a cipher using SM4 block cipher algorithm in CBC mode with 128-bit input blocks.static final byteTheCIPHER_SM4_ECBconstant represents a cipher using SM4 block cipher algorithm in CBC mode with 128-bit input blocks.static final byteUsed ininit()methods to indicate decryption mode.static final byteUsed ininit()methods to indicate encryption mode.static final bytePadding algorithmPAD_ISO9796choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method to create a Signature object instance.static final bytePadding algorithmPAD_ISO9796_MRchoice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method to create a SignatureMessageRecovery object instance.static final bytePadding algorithmPAD_ISO9796_MR_SCHEME_1_OPT_2choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method to create a SignatureMessageRecovery object instance.static final bytePadding algorithmPAD_ISO9796_MR_SCHEME_2choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method to create a SignatureMessageRecovery object instance.static final bytePadding algorithmPAD_ISO9796_MR_SCHEME_2_OPT_2choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method to create a SignatureMessageRecovery object instance.static final bytePadding algorithmPAD_ISO9796_MR_SCHEME_3choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method to create a SignatureMessageRecovery object instance.static final bytePadding algorithmPAD_ISO9796_MR_SCHEME_3_OPT_2choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method to create a SignatureMessageRecovery object instance.static final bytePadding algorithmPAD_ISO9797_1_M1_ALG3choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method.static final bytePadding algorithmPAD_ISO9797_1_M2_ALG3choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method.static final bytePadding algorithmPAD_ISO9797_M1choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method and theSignature.getInstance(byte, byte, byte, boolean)method.static final bytePadding algorithmPAD_ISO9797_M2choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method and theSignature.getInstance(byte, byte, byte, boolean)method.static final bytePadding algorithmPAD_NOPADchoice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method and theSignature.getInstance(byte, byte, byte, boolean)method.static final byteThis constant indicates that there is no discrete padding algorithm.static final bytePadding algorithmPAD_PKCS1choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method and theSignature.getInstance(byte, byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEPchoice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_EXT_PARAMETERSchoice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_SHA224choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_SHA256choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_SHA3_224choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_SHA3_256choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_SHA3_384choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_SHA3_512choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_SHA384choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_OAEP_SHA512choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_PSSchoice for the paddingAlgorithm parameter theSignature.getInstance(byte, byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS1_PSS_EXT_PARAMETERSchoice for the paddingAlgorithm parameter theSignature.getInstance(byte, byte, byte, boolean)method.static final bytePadding algorithmPAD_PKCS5choice for the paddingAlgorithm parameter of thegetInstance(byte, byte, boolean)method and theSignature.getInstance(byte, byte, byte, boolean)method.static final bytePadding algorithmPAD_RFC2409choice for the paddingAlgorithm parameter of theSignature.getInstance(byte, byte, byte, boolean)method. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes and releases this JCRE owned temporary instance of theOneShotobject for reuse.shortdoFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) Generates encrypted/decrypted output from all/last input data.byteGets the Cipher algorithm.byteGets the raw cipher algorithm.byteGets the padding algorithm.voidInitializes theCipherobject with the appropriateKey.voidInitializes theCipherobject with the appropriate Key and algorithm specific parameters.static final Cipher.OneShotopen(byte cipherAlgorithm, byte paddingAlgorithm) Opens/acquires a JCRE owned temporary Entry Point Object instance ofOneShotwith the selected cipher algorithm and padding algorithm.shortupdate(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) Always throws aCryptoException.Methods inherited from class Cipher
getInstance, getInstanceModifier and TypeMethodDescriptionstatic final CiphergetInstance(byte algorithm, boolean externalAccess) Creates aCipherobject instance of the selected algorithm.static final CiphergetInstance(byte cipherAlgorithm, byte paddingAlgorithm, boolean externalAccess) Creates aCipherobject instance with the selected of the selected raw cipher algorithm and padding algorithm.
-
Method Details
-
open
public static final Cipher.OneShot open(byte cipherAlgorithm, byte paddingAlgorithm) throws CryptoException Opens/acquires a JCRE owned temporary Entry Point Object instance ofOneShotwith the selected cipher algorithm and padding algorithm.Note:
- When the padding algorithm is built into the cipher algorithm use
the
PAD_NULLchoice for the padding algorithm.
- Parameters:
cipherAlgorithm- the desired cipher algorithm. Valid codes listed inCIPHER_*constants in this class e.g.CIPHER_AES_CBC.paddingAlgorithm- the desired padding algorithm. Valid codes listed inPAD_*constants in the Cipher class e.g.PAD_NULL.- Returns:
- the
OneShotobject instance of the requested algorithm. - Throws:
CryptoException- with the following reason codes:CryptoException.NO_SUCH_ALGORITHMif the requested cipher algorithm or padding algorithm or their combination is not supported.
SystemException- with the following reason codes:SystemException.NO_RESOURCEif sufficient resources are not available.
- When the padding algorithm is built into the cipher algorithm use
the
-
close
public void close()Closes and releases this JCRE owned temporary instance of theOneShotobject for reuse. If this method is called again this method does nothing.- Throws:
SecurityException- if this JCRE owned temporary instance of theOneShotobject was opened in a context different from that of the caller.
-
update
public short update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws CryptoException Always throws aCryptoException. This method is not supported byOneShot.- Specified by:
updatein classCipher- Parameters:
inBuff- the input buffer of data to be encrypted/decryptedinOffset- the offset into the input buffer at which to begin encryption/decryptioninLength- the byte length to be encrypted/decryptedoutBuff- the output buffer, may be the same as the input bufferoutOffset- the offset into the output buffer where the resulting ciphertext/plaintext begins- Returns:
- number of bytes output in
outBuff - Throws:
CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEalways.
-
init
Initializes theCipherobject with the appropriateKey. This method should be used for algorithms which do not need initialization parameters or use default parameter values.init()must be used to update theCipherobject with a new key. If theKeyobject is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.The
Keyis checked for consistency with theCipheralgorithm. For example, the key type must be matched. For elliptic curve algorithms, the key must represent a valid point on the curve's domain parameters. Additional key component/domain parameter strength checks are implementation specific.Note:
- AES, DES, triple DES, Korean SEED and SM4 algorithms used in modes requiring an initial vector (like CBC, CFB, CTR, XTS modes) will use 0 for initial vector(IV) if this method is used.
- Specified by:
initin classCipher- Parameters:
theKey- the key object to use for encrypting or decryptingtheMode- one ofMODE_DECRYPTorMODE_ENCRYPT- Throws:
SecurityException- if this JCRE owned temporary instance of theOneShotobject was opened in a context different from that of the caller.CryptoException- with the following reason codes:CryptoException.ILLEGAL_VALUEiftheModeoption is an undefined value or if theKeyis inconsistent with theCipherimplementation.CryptoException.UNINITIALIZED_KEYiftheKeyinstance is uninitialized.
-
init
public void init(Key theKey, byte theMode, byte[] bArray, short bOff, short bLen) throws CryptoException Initializes theCipherobject with the appropriate Key and algorithm specific parameters.init()must be used to update theCipherobject with a new key. If theKeyobject is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.The
Keyis checked for consistency with theCipheralgorithm. For example, the key type must be matched. For elliptic curve algorithms, the key must represent a valid point on the curve's domain parameters. Additional key component/domain parameter strength checks are implementation specific.Note:
- DES and triple DES algorithms in CBC mode expect an 8-byte parameter value for
the initial vector(IV) in
bArray. - AES algorithms expect a 16-byte parameter value in
bArrayfor the initial vector(IV) in CBC, CFB, CTR mode or for the value of the 128-bit tweak in XTS mode. The 128-bit tweak in XTS mode is an unsigned value with Big-Endian byte order which may contain leading zeroes. - Korean SEED algorithms in CBC mode expect a 16-byte parameter value for
the initial vector(IV) in
bArray. - SM4 algorithms in CBC mode expect a 16-byte parameter value for
the initial vector(IV) in
bArray. - AES algorithms in ECB mode, DES algorithms in ECB mode, Korean SEED algorithm in ECB mode,
SM4 in ECB mode, DSA and SM2 algorithms throw
CryptoException.ILLEGAL_VALUE. - For RSA:
- Algorithms using the padding scheme
PAD_PKCS1_OAEP_EXT_PARAMETERSexpect a two-byte parameter value (b1 b2)in bArray where the first byte parameter b1 represents the message digest algorithm of the scheme and the second byte parameter b2 represents the message digest algorithm of MGF1. In both cases, valid codes are listed in ALG_* constants in the MessageDigest class or 0xFF. Notes:- if b1 is equal to 0xFF, the digest algorithm of the OAEP scheme must fall back to the default value i.e SHA1
- if b2 is equal to 0xFF, the MGF1 digest algorithm must fall back to the default value i.e SHA1
- All other algorithms throw CryptoException.ILLEGAL_VALUE
- Algorithms using the padding scheme
- Specified by:
initin classCipher- Parameters:
theKey- the key object to use for encrypting or decrypting.theMode- one ofMODE_DECRYPTorMODE_ENCRYPTbArray- byte array containing algorithm specific initialization infobOff- offset within bArray where the algorithm specific data beginsbLen- byte length of algorithm specific parameter data- Throws:
SecurityException- if this JCRE owned temporary instance of theOneShotobject was opened in a context different from that of the caller.CryptoException- with the following reason codes:CryptoException.NO_SUCH_ALGORITHMif the specified algorithm parameters are not supported that is when the specified digest algorithm for the OAEP scheme and/or the specified digest algorithm for MGF1 is/are not supported in case of RSA algorithms with the padding schemePAD_PKCS1_OAEP_EXT_PARAMETERS.CryptoException.ILLEGAL_VALUEiftheModeoption is an undefined value or if a byte array parameter option is not supported by the algorithm or if thebLenis an incorrect byte length for the algorithm specific data or if theKeyis inconsistent with theCipherimplementation.CryptoException.UNINITIALIZED_KEYiftheKeyinstance is uninitialized.
- DES and triple DES algorithms in CBC mode expect an 8-byte parameter value for
the initial vector(IV) in
-
getAlgorithm
public byte getAlgorithm()Gets the Cipher algorithm.- Specified by:
getAlgorithmin classCipher- Returns:
- the algorithm code defined above; if the algorithm is not one of the pre-defined
algorithms,
0is returned. - Throws:
SecurityException- if this JCRE owned temporary instance of theOneShotobject was opened in a context different from that of the caller.- See Also:
-
getCipherAlgorithm
public byte getCipherAlgorithm()Gets the raw cipher algorithm. Pre-defined codes listed inCIPHER_*constants in this class e.g.CIPHER_AES_CBC.- Specified by:
getCipherAlgorithmin classCipher- Returns:
- the raw cipher algorithm code defined above; if the algorithm is not
one of the pre-defined algorithms,
0is returned. - Throws:
SecurityException- if this JCRE owned temporary instance of theOneShotobject was opened in a context different from that of the caller.
-
getPaddingAlgorithm
public byte getPaddingAlgorithm()Gets the padding algorithm. Pre-defined codes listed inPAD_*constants in this class e.g.PAD_NULL.- Specified by:
getPaddingAlgorithmin classCipher- Returns:
- the padding algorithm code defined in the
Cipherclass; if the algorithm is not one of the pre-defined algorithms,0is returned. - Throws:
SecurityException- if this JCRE owned temporary instance of theOneShotobject was opened in a context different from that of the caller.
-
doFinal
public short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws CryptoException Generates encrypted/decrypted output from all/last input data. This method must be invoked to complete a cipher operation. This method processes any remaining input data buffered by one or more calls to theupdate()method as well as input data supplied in theinBuffparameter.A call to this method also resets this
Cipherobject to a state where:- the key and the mode are the same as when previously initialized via a call to
init(Key, byte)orinit(Key, byte, byte[], short, short). - other initial values are the same default values as after a call to
init(Key, byte). For example:- AES, DES, triple DES, Korean SEED and SM4 algorithms used in modes requiring an initial vector (like CBC, CFB, CTR, XTS modes) will use 0 for initial vector(IV).
- RSA algorithm used with the PKCS#1-OAEP scheme, will use default values for the message digest algorithm of the scheme and the message digest algorithm for MGF1 as specified in the description of the related constants.
init(Key, byte, byte[], short, short)method.Notes:
- When using block-aligned data (multiple of block size),
if the input buffer,
inBuffand the output buffer,outBuffrefer to the same array, or if any of these arguments refer to an array view sharing components with the other argument, then the output data area must not partially overlap the input data area such that the input data is modified before it is used.
Example: ifinBuff==outBuffandinOffset < outOffset < inOffset+inLength, incorrect output may result. - When non-block aligned data is presented as input data, no amount of input
and output buffer data overlap is allowed.
Example: ifinBuff==outBuffandoutOffset < inOffset+inLength, incorrect output may result. - On decryption operations (except when ISO 9797 method 1 padding is used),
the padding bytes are not written to
outBuff. - On encryption and decryption operations, the number of bytes output into
outBuffmay be larger or smaller thaninLengthor even 0. - On decryption operations resulting in an
ArrayIndexOutOfBoundsException,outBuffmay be partially modified.
In addition to returning a
shortresult, this method sets the result in an internal state which can be rechecked using assertion methods of theSensitiveResultclass, if supported by the platform.- Specified by:
doFinalin classCipher- Parameters:
inBuff- the input buffer of data to be encrypted/decryptedinOffset- the offset into the input buffer at which to begin encryption/decryptioninLength- the byte length to be encrypted/decryptedoutBuff- the output buffer, may be the same as the input bufferoutOffset- the offset into the output buffer where the resulting output data begins- Returns:
- number of bytes output in
outBuff - Throws:
SecurityException- if this JCRE owned temporary instance of theOneShotobject was opened in a context different from that of the caller.CryptoException- with the following reason codes:CryptoException.UNINITIALIZED_KEYif key not initialized.CryptoException.INVALID_INITif thisCipherobject is not initialized.CryptoException.ILLEGAL_USEif one of the following conditions is met:- This
Cipheralgorithm does not pad the message and the message is not block aligned. - This
Cipheralgorithm does not pad the message and no input data has been provided ininBuffor via theupdate()method. - The input message length is not supported or the message value is greater than or equal to the modulus.
- The decrypted data is not bounded by appropriate padding bytes.
- This
- the key and the mode are the same as when previously initialized via a call to
-