Stay organized with collections
Save and categorize content based on your preferences.
GCMParameterSpec
open class GCMParameterSpec : AlgorithmParameterSpec
Specifies the set of parameters required by a using the Galois/Counter Mode (GCM) mode.
Simple block cipher modes (such as CBC) generally require only an initialization vector (such as IvParameterSpec
), but GCM needs these parameters:
IV
: Initialization Vector (IV)
tLen
: length (in bits) of authentication tag T
In addition to the parameters described here, other GCM inputs/output (Additional Authenticated Data (AAD), Keys, block ciphers, plain/ciphertext and authentication tags) are handled in the Cipher
class.
Please see RFC 5116 for more information on the Authenticated Encryption with Associated Data (AEAD) algorithm, and NIST Special Publication 800-38D, "NIST Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC."
The GCM specification states that tLen
may only have the values {128, 120, 112, 104, 96}, or {64, 32} for certain applications. Other values can be specified for this class, but not all CSP implementations will support them.
Summary
Public constructors |
Constructs a GCMParameterSpec using the specified authentication tag bit-length and IV buffer.
|
Constructs a GCMParameterSpec object using the specified authentication tag bit-length and a subset of the specified buffer as the IV.
|
Public methods |
open ByteArray! |
Returns the Initialization Vector (IV).
|
open Int |
Returns the authentication tag length.
|
Public constructors
GCMParameterSpec
GCMParameterSpec(
tLen: Int,
src: ByteArray!)
Constructs a GCMParameterSpec using the specified authentication tag bit-length and IV buffer.
Parameters |
tLen |
Int: the authentication tag length (in bits) |
src |
ByteArray!: the IV source buffer. The contents of the buffer are copied to protect against subsequent modification. |
Exceptions |
java.lang.IllegalArgumentException |
if tLen is negative, or src is null. |
GCMParameterSpec
GCMParameterSpec(
tLen: Int,
src: ByteArray!,
offset: Int,
len: Int)
Constructs a GCMParameterSpec object using the specified authentication tag bit-length and a subset of the specified buffer as the IV.
Parameters |
tLen |
Int: the authentication tag length (in bits) |
src |
ByteArray!: the IV source buffer. The contents of the buffer are copied to protect against subsequent modification. |
offset |
Int: the offset in src where the IV starts |
len |
Int: the number of IV bytes |
Exceptions |
java.lang.IllegalArgumentException |
if tLen is negative, src is null, len or offset is negative, or the sum of offset and len is greater than the length of the src byte array. |
Public methods
getIV
open fun getIV(): ByteArray!
Returns the Initialization Vector (IV).
Return |
ByteArray! |
the IV. Creates a new array each time this method is called. |
getTLen
open fun getTLen(): Int
Returns the authentication tag length.
Return |
Int |
the authentication tag length (in bits) |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# GCMParameterSpec\n\nAdded in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nGCMParameterSpec\n================\n\n```\nopen class GCMParameterSpec : AlgorithmParameterSpec\n```\n\n|---|-----------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [javax.crypto.spec.GCMParameterSpec](#) |\n\nSpecifies the set of parameters required by a using the Galois/Counter Mode (GCM) mode.\n\nSimple block cipher modes (such as CBC) generally require only an initialization vector (such as `IvParameterSpec`), but GCM needs these parameters:\n\n- `IV`: Initialization Vector (IV)\n- `tLen`: length (in bits) of authentication tag T\n\nIn addition to the parameters described here, other GCM inputs/output (Additional Authenticated Data (AAD), Keys, block ciphers, plain/ciphertext and authentication tags) are handled in the `Cipher` class.\n\nPlease see [RFC 5116](http://www.ietf.org/rfc/rfc5116.txt) for more information on the Authenticated Encryption with Associated Data (AEAD) algorithm, and [NIST Special Publication 800-38D](http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf), \"NIST Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC.\"\n\nThe GCM specification states that `tLen` may only have the values {128, 120, 112, 104, 96}, or {64, 32} for certain applications. Other values can be specified for this class, but not all CSP implementations will support them.\n\nSummary\n-------\n\n| Public constructors ||\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [GCMParameterSpec](#GCMParameterSpec(kotlin.Int,%20kotlin.ByteArray))`(`tLen:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `src:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!`)` Constructs a GCMParameterSpec using the specified authentication tag bit-length and IV buffer. |\n| [GCMParameterSpec](#GCMParameterSpec(kotlin.Int,%20kotlin.ByteArray,%20kotlin.Int,%20kotlin.Int))`(`tLen:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `src:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!`, `offset:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `len:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Constructs a GCMParameterSpec object using the specified authentication tag bit-length and a subset of the specified buffer as the IV. |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------|\n| open [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)! | [getIV](#getIV())`()` Returns the Initialization Vector (IV). |\n| open [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [getTLen](#getTLen())`()` Returns the authentication tag length. |\n\nPublic constructors\n-------------------\n\n### GCMParameterSpec\n\nAdded in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nGCMParameterSpec(\n tLen: Int, \n src: ByteArray!)\n```\n\nConstructs a GCMParameterSpec using the specified authentication tag bit-length and IV buffer.\n\n| Parameters ||\n|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `tLen` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the authentication tag length (in bits) |\n| `src` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!: the IV source buffer. The contents of the buffer are copied to protect against subsequent modification. |\n\n| Exceptions ||\n|--------------------------------------|------------------------------------------|\n| `java.lang.IllegalArgumentException` | if `tLen` is negative, or `src` is null. |\n\n### GCMParameterSpec\n\nAdded in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nGCMParameterSpec(\n tLen: Int, \n src: ByteArray!, \n offset: Int, \n len: Int)\n```\n\nConstructs a GCMParameterSpec object using the specified authentication tag bit-length and a subset of the specified buffer as the IV.\n\n| Parameters ||\n|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `tLen` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the authentication tag length (in bits) |\n| `src` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!: the IV source buffer. The contents of the buffer are copied to protect against subsequent modification. |\n| `offset` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the offset in `src` where the IV starts |\n| `len` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the number of IV bytes |\n\n| Exceptions ||\n|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `java.lang.IllegalArgumentException` | if `tLen` is negative, `src` is null, `len` or `offset` is negative, or the sum of `offset` and `len` is greater than the length of the `src` byte array. |\n\nPublic methods\n--------------\n\n### getIV\n\nAdded in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getIV(): ByteArray!\n```\n\nReturns the Initialization Vector (IV).\n\n| Return ||\n|------------------------------------------------------------------------------------------|--------------------------------------------------------------|\n| [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)! | the IV. Creates a new array each time this method is called. |\n\n### getTLen\n\nAdded in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getTLen(): Int\n```\n\nReturns the authentication tag length.\n\n| Return ||\n|----------------------------------------------------------------------------|-----------------------------------------|\n| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the authentication tag length (in bits) |"]]