Package uicc.usim.gba_u
Class GBAUCipher.OneShot
java.lang.Object
uicc.usim.gba_u.GBAUCipher
uicc.usim.gba_u.GBAUCipher.OneShot
- Enclosing class:
- GBAUCipher
The
Note:
The following code shows a typical usage pattern for the
OneShot class is a specialization of the GBAUCipher 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 GBAUCipher-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 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 tight try-catch-finally blocks (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 to null once the instance is closed in order to prevent further use attempts. - Upon return from any Applet entry point method, back to the JCRE, and on tear or card reset events any
OneShotinstances 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.
...
GBAUCipher.OneShot enc = null;
try {
enc = GBAUCipher.OneShot.open(Cipher.CIPHER_AES_CBC, Cipher.PAD_PKCS5);
enc.init( Cipher.MODE_ENCRYPT, adfAID, adfAIDOff, adfAIDLen, nafID, nafIDOff, nafIDLen );
enc.doFinal(someInData, (short) 0, (short) someInData.length, encData, (short) 0);
} catch (CryptoException ce) {
// Handle exception
} finally {
if (enc != null) {
enc.close();
enc = null;
}
}
...
-
Nested Class Summary
Nested classes/interfaces inherited from class uicc.usim.gba_u.GBAUCipher
GBAUCipher.OneShot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes and releases this JCRE owned temporary instance of the OneShot object for reuse.shortdoFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) Generates encrypted/decrypted output from all/last input data using Ks_int_NAF linked to NAF ID given ininit().byteGets the cipher algorithm.byteGets the raw cipher algorithm.byteGets the padding algorithm.voidinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen) Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key).voidinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen) Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key) and algorithm specific parameters.voidinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength) Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key) and algorithm specific parameters.voidinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength) Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key).static GBAUCipher.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 a CryptoException.Methods inherited from class uicc.usim.gba_u.GBAUCipher
getInstance, getInstance
-
Constructor Details
-
OneShot
protected OneShot()Protected constructor
-
-
Method Details
-
open
public static GBAUCipher.OneShot open(byte cipherAlgorithm, byte paddingAlgorithm) throws javacard.security.CryptoException Opens/acquires a JCRE owned temporary Entry Point Object instance ofOneShotwith the selected cipher algorithm and padding algorithm.
Ks_int_NAF keys, internal keys generated during GBA_U process (see 3GPP TS 31.102 and 3GPP TS 33.220), are the only ones used in this class.
Ks_int_NAF keys are 256 bits symmetric keys then all asymmetric key algorithms are not supported.
- Parameters:
cipherAlgorithm- the desired cipher algorithm. Valid codes listed inCIPHER_*constants in thisGBAUCipherorCipherclass fromjavacardx.cryptopackage e.g.CIPHER_AES_CBC.paddingAlgorithm- the desired padding algorithm. Valid codes listed inPAD_*constants inGBAUCipherclass orCipherclass fromjavacardx.cryptopackage e.g.PAD_NULL.- Returns:
- the
OneShotobject instance of the requested algorithm. - Throws:
javacard.security.CryptoException- with the following reason codes:CryptoException.NO_SUCH_ALGORITHMif the requested cipher algorithm or padding algorithm or their combination is not supported.
javacard.framework.SystemException- with the following reason codes:SystemException.NO_SUCH_ALGORITHMif sufficient resources are not available.
- See Also:
-
close
Closes and releases this JCRE owned temporary instance of the OneShot object for reuse. If this method is called again this method does nothing.- Throws:
SecurityException- if this JCRE owned temporary instance of the OneShot object was opened in a context different from that of the caller.- See Also:
-
init
public void init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen) throws GBAUException, javacard.security.CryptoException Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key). This method should be used for algorithms which do not need initialization parameters or use default parameter values.
init()must be used to update theGBAUCipherobject with a new key / NAF ID. If the Ks_int_NAF key is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.
Ifinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)is used, the key length is implicitly selected:- AES will use the Ks_int_NAF on 256 bits.
- Korean SEED will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
- SM4 will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
Useinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)for different key length.- Specified by:
initin classGBAUCipher- Parameters:
theMode- one ofjavacardx.crypto.Cipher.MODE_DECRYPTorjavacardx.crypto.Cipher.MODE_ENCRYPTadfAID- byte array containing the value of complete ADF AID to use (e.g. USIM, ISIM), partial AID is not supportedadfAIDOff- offset within adfAID where the ADF AID value beginsadfAIDLen- byte length of ADF AID valuenafID- byte array containing the value of NAF IDnafIDOff- offset within nafID where the NAF ID value beginsnafIDLen- byte length of NAF ID value- Throws:
GBAUException- with the following reason codes:GBA_U_BOOTSTRAP_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U Bootstrap procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_NAF_DERIVATION_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U NAF derivation procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_UNALLOWED_ACCESSif applet is not allowed to use API, see 3GPP TS 31.130 for detail on access condition requiredGBA_U_INCORRECT_NAF_IDif applet provides a NAF ID (throughnafID,nafIDOffandnafIDLen) which is not defined in its access condition, see 3GPP TS 31.130 for detail on access condition and NAF ID associationGBA_U_INCORRECT_ADF_AIDif applet provides a ADF AID (throughadfAID,adfAIDOffandadfAIDLen) which does not supported GBA_U computation
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEif one of the following conditions is met:- if theMode option is an undefined value.
- if key size is incompatible with algorithm defined in open().
NullPointerException- ifadfAIDornafIDisnullArrayIndexOutOfBoundsException- if the check operation onadfAIDOfforadfAIDLenwould cause access of data outsideadfAIDarray boundsArrayIndexOutOfBoundsException- if the check operation onnafIDOffornafIDLenwould cause access of data outsidenafIDarray bounds- See Also:
-
open(byte cipherAlgorithm, byte paddingAlgorithm)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
-
init
public void init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength) throws GBAUException, javacard.security.CryptoException Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key). This method should be used for algorithms which do not need initialization parameters or use default parameter values.
init()must be used to update theGBAUCipherobject with a new key / NAF ID. If the Ks_int_NAF key is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.
Depending onkeyLengthparameter the key is retrieved from Ks_int_NAF as follows:LENGTH_AES_128will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_AES_192will use the 192 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_AES_256will use all the 256 bits of the Ks_int_NAF 256 bits key.LENGTH_KOREAN_SEED_128Korean SEED will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_SM4will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
- Specified by:
initin classGBAUCipher- Parameters:
theMode- one ofjavacardx.crypto.Cipher.MODE_DECRYPTorjavacardx.crypto.Cipher.MODE_ENCRYPTadfAID- byte array containing the value of complete ADF AID to use (e.g. USIM, ISIM), partial AID is not supportedadfAIDOff- offset within adfAID where the ADF AID value beginsadfAIDLen- byte length of ADF AID valuenafID- byte array containing the value of NAF IDnafIDOff- offset within nafID where the NAF ID value beginsnafIDLen- byte length of NAF ID valuekeyLength- the key size in bits. The valid key bit length is key type dependent. Some common key lengths are listed inLENGTH_*constants in theKeyBuilderclass fromjavacard.securitye.g.LENGTH_AES_128.- Throws:
GBAUException- with the following reason codes:GBA_U_BOOTSTRAP_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U Bootstrap procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_NAF_DERIVATION_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U NAF derivation procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_UNALLOWED_ACCESSif applet is not allowed to use API, see 3GPP TS 31.130 for detail on access condition requiredGBA_U_INCORRECT_NAF_IDif applet provides a NAF ID (throughnafID,nafIDOffandnafIDLen) which is not defined in its access condition, see 3GPP TS 31.130 for detail on access condition and NAF ID associationGBA_U_INCORRECT_ADF_AIDif applet provides a ADF AID (throughadfAID,adfAIDOffandadfAIDLen) which does not supported GBA_U computation
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEif one of the following conditions is met:- if theMode option is an undefined value.
- if keyLength is incompatible with algorithm defined in open().
NullPointerException- ifadfAIDornafIDisnullArrayIndexOutOfBoundsException- if the check operation onadfAIDOfforadfAIDLenwould cause access of data outsideadfAIDarray boundsArrayIndexOutOfBoundsException- if the check operation onnafIDOffornafIDLenwould cause access of data outsidenafIDarray bounds- Since:
- 1.2
- See Also:
-
open(byte cipherAlgorithm, byte paddingAlgorithm)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
-
init
public void init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen) throws GBAUException, javacard.security.CryptoException Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key) and algorithm specific parameters.
init()must be used to update theGBAUCipherobject with a new key / NAF ID. If the Ks_int_NAF key is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.
Ifinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)is used, the key length is implicitly selected:- AES will use the Ks_int_NAF on 256 bits.
- Korean SEED will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
- SM4 will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
Useinit(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)for different key length.- Specified by:
initin classGBAUCipher- Parameters:
theMode- one ofjavacardx.crypto.Cipher.MODE_DECRYPTorjavacardx.crypto.Cipher.MODE_ENCRYPTadfAID- byte array containing the value of complete ADF AID to use (e.g. USIM, ISIM), partial AID is not supportedadfAIDOff- offset within adfAID where the ADF AID value beginsadfAIDLen- byte length of ADF AID valuenafID- byte array containing the value of NAF IDnafIDOff- offset within nafID where the NAF ID value beginsnafIDLen- byte length of NAF ID valuebArray- byte array containing algorithm specific initialization infobOff- offset within bArray where the algorithm specific data beginsbLen- byte length of algorithm specific parameter data- Throws:
GBAUException- with the following reason codes:GBA_U_BOOTSTRAP_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U Bootstrap procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_NAF_DERIVATION_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U NAF derivation procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_UNALLOWED_ACCESSif applet is not allowed to use API, see 3GPP TS 31.130 for detail on access condition requiredGBA_U_INCORRECT_NAF_IDif applet provides a NAF ID (throughnafID,nafIDOffandnafIDLen) which is not defined in its access condition, see 3GPP TS 31.130 for detail on access condition and NAF ID associationGBA_U_INCORRECT_ADF_AIDif applet provides a ADF AID (throughadfAID,adfAIDOffandadfAIDLen) which does not supported GBA_U computation
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEif one of the following conditions is met:- if theMode option is an undefined value.
- if key size is incompatible with algorithm defined in open().
NullPointerException- ifadfAID,nafIDorbArrayisnullArrayIndexOutOfBoundsException- if the check operation onadfAIDOfforadfAIDLenwould cause access of data outsideadfAIDarray boundsArrayIndexOutOfBoundsException- if the check operation onnafIDOffornafIDLenwould cause access of data outsidenafIDarray boundsArrayIndexOutOfBoundsException- if the check operation onbOfforbLenwould cause access of data outsidebArrayarray bounds- See Also:
-
open(byte cipherAlgorithm, byte paddingAlgorithm)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
-
init
public void init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength) throws GBAUException, javacard.security.CryptoException Initializes theGBAUCipherobject with the appropriate NAF ID (then Ks_int_NAF key) and algorithm specific parameters.
init()must be used to update theGBAUCipherobject with a new key / NAF ID. If the Ks_int_NAF key is modified after invoking theinit()method, the behavior of theupdate()anddoFinal()methods is unspecified.
Depending onkeyLengthparameter the key is retrieved from Ks_int_NAF as follows:LENGTH_AES_128will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_AES_192will use the 192 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_AES_256will use all the 256 bits of the Ks_int_NAF 256 bits key.LENGTH_KOREAN_SEED_128Korean SEED will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.LENGTH_SM4will use the 128 left most significant bits of the Ks_int_NAF 256 bits key.
- Specified by:
initin classGBAUCipher- Parameters:
theMode- one ofjavacardx.crypto.Cipher.MODE_DECRYPTorjavacardx.crypto.Cipher.MODE_ENCRYPTadfAID- byte array containing the value of complete ADF AID to use (e.g. USIM, ISIM), partial AID is not supportedadfAIDOff- offset within adfAID where the ADF AID value beginsadfAIDLen- byte length of ADF AID valuenafID- byte array containing the value of NAF IDnafIDOff- offset within nafID where the NAF ID value beginsnafIDLen- byte length of NAF ID valuebArray- byte array containing algorithm specific initialization infobOff- offset within bArray where the algorithm specific data beginsbLen- byte length of algorithm specific parameter datakeyLength- the key size in bits. The valid key bit length is key type dependent. Some common key lengths are listed inLENGTH_*constants in theKeyBuilderclass fromjavacard.securitye.g.LENGTH_AES_128.- Throws:
GBAUException- with the following reason codes:GBA_U_BOOTSTRAP_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U Bootstrap procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_NAF_DERIVATION_NOT_DONEif Ks_int_NAF is not availaible linked to GBA_U NAF derivation procedure was not done (see 3GPP TS 31.102 and 3GPP TS 33.220)GBA_U_UNALLOWED_ACCESSif applet is not allowed to use API, see 3GPP TS 31.130 for detail on access condition requiredGBA_U_INCORRECT_NAF_IDif applet provides a NAF ID (throughnafID,nafIDOffandnafIDLen) which is not defined in its access condition, see 3GPP TS 31.130 for detail on access condition and NAF ID associationGBA_U_INCORRECT_ADF_AIDif applet provides a ADF AID (throughadfAID,adfAIDOffandadfAIDLen) which does not supported GBA_U computation
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEif one of the following conditions is met:- if theMode option is an undefined value.
- if keyLength is incompatible with algorithm defined in open().
NullPointerException- ifadfAIDornafIDisnullArrayIndexOutOfBoundsException- if the check operation onadfAIDOfforadfAIDLenwould cause access of data outsideadfAIDarray boundsArrayIndexOutOfBoundsException- if the check operation onnafIDOffornafIDLenwould cause access of data outsidenafIDarray boundsArrayIndexOutOfBoundsException- if the check operation onbOfforbLenwould cause access of data outsidebArrayarray bounds- See Also:
-
open(byte cipherAlgorithm, byte paddingAlgorithm)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
-
getAlgorithm
public byte getAlgorithm()Gets the cipher algorithm. Pre-defined codes listed inALG_*constants injavacardx.crypto.Ciphere.g.ALG_AES_BLOCK_128_CBC_NOPAD.- Specified by:
getAlgorithmin classGBAUCipher- Returns:
- the algorithm code defined above; if the algorithm is not one of the pre-defined algorithms, 0 is returned.
- See Also:
-
getCipherAlgorithm
public byte getCipherAlgorithm()Gets the raw cipher algorithm. Pre-defined codes listed inCIPHER_*constants injavacardx.crypto.Ciphere.g. CIPHER_AES_CBC.- Specified by:
getCipherAlgorithmin classGBAUCipher- Returns:
- the raw cipher algorithm code defined above; if the algorithm is not one of the pre-defined algorithms, 0 is returned.
- See Also:
-
getPaddingAlgorithm
public byte getPaddingAlgorithm()Gets the padding algorithm. Pre-defined codes listed inPAD_*constants injavacardx.crypto.Ciphere.g. PAD_NULL.- Specified by:
getPaddingAlgorithmin classGBAUCipher- Returns:
- the padding algorithm code defined in the Cipher class; if the algorithm is not one of the pre-defined algorithms, 0 is returned.
- See Also:
-
update
public short update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws javacard.security.CryptoException Always throws a CryptoException. This method is not supported byOneShot.- Specified by:
updatein classGBAUCipher- 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:
javacard.security.CryptoException- with the following reason codes:CryptoException.ILLEGAL_USEalways.
- See Also:
-
open(byte cipherAlgorithm, byte paddingAlgorithm)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
-
doFinal
public short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws javacard.security.CryptoException Generates encrypted/decrypted output from all/last input data using Ks_int_NAF linked to NAF ID given ininit(). 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 Cipher object to the state it was in when previously initialized via a call toinit()methods. That is, the object is reset and available to encrypt or decrypt (depending on the operation mode that was specified in the call toinit()methods) more data. In addition, note that the initial vector(IV) used in AES, DES, Korean SEED and SM4 algorithms will be reset to 0.
Note:- When using block-aligned data (multiple of block size), if the input buffer,
inBuffand the output buffer,outBuffare the same array, then the output data area must not partially overlap the input data area such that the input data is modified before it is used; 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;
if
inBuff==outBuffandoutOffset < inOffset+inLength, incorrect output may result. - AES, DES, triple DES, Korean SEED and SM4 algorithms in CBC mode reset the initial vector(IV) to 0.
The initial vector(IV) can be re-initialized using the
init()methods. - 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 than inLength or even 0. - On decryption operations resulting in an
ArrayIndexOutOfBoundsException,outBuffmay be partially modified.
- Specified by:
doFinalin classGBAUCipher- 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:
javacard.security.CryptoException- with the following reason codes:CryptoException.UNINITIALIZED_KEYif the key (Ks_int_NAF key) is uninitialized.CryptoException.INVALID_INITif thisGBAUCipherobject is not initialized.CryptoException.ILLEGAL_USEif one of the following conditions is met- This
GBAUCipheralgorithm does not pad the message and the message is not block aligned. - This
GBAUCipheralgorithm does not pad the message and no input data has been provided ininBuffor via theupdate()method. - The decrypted data is not bounded by appropriate padding bytes.
- This
NullPointerException- ifinBufforoutOffsetisnullArrayIndexOutOfBoundsException- if the check operation oninBufforoutOffsetwould cause access of data outside array bounds- See Also:
-
open(byte cipherAlgorithm, byte paddingAlgorithm)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, short keyLength)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen)init(byte theMode, byte[] adfAID, short adfAIDOff, short adfAIDLen, byte[] nafID, short nafIDOff, short nafIDLen, byte[] bArray, short bOff, short bLen, short keyLength)update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
- When using block-aligned data (multiple of block size), if the input buffer,
-