public class SM9KEMKeyGeneratorSpi
extends javax.crypto.KeyGeneratorSpi
KeyGenerator bridge for the SM9 key encapsulation mechanism
(GM/T 0044.4-2016). Registered as KeyGenerator.SM9-KEM; initialise with:
KEMGenerateSpec to encapsulate - its PublicKey must be the
recipient's SM9EncUserPublicKey, from
SM9EncMasterPublicKey.getUserPublicKey(byte[]); orKEMExtractSpec to decapsulate - its PrivateKey must be the
recipient's SM9EncUserPrivateKey, the KEM /
decryption key from the KGC.keySizeInBits) drives SM9's own
GM/T 0044.4 KDF, which produces the shared key directly; the spec's generic KDF
fields are therefore not applied (an external KDF on top would break interoperability
with other GM/T 0044.4 implementations - callers who want one anyway can layer it via
the javax.crypto.KEM API, KEM.SM9-KEM, with a KTSParameterSpec KDF).
A spec that asks for something this cannot honour - a KDF other than the specs' default,
or any otherInfo - is refused rather than quietly served as if it had not asked.
engineGenerateKey returns a SecretKeyWithEncapsulation.
Usage warning: an identity's key should be used for this service or for
Cipher.SM9, but not for both. A deployment needing both has its KGC publish a
separate hid for each function, as it already does for the key exchange, so that the two
keys are distinct. init also refuses for decapsulation a key declared for decryption,
and one that has been used for it - see
SM9EncPrivateKeyParameters.recordUsage(int).
| Constructor and Description |
|---|
SM9KEMKeyGeneratorSpi() |
| Modifier and Type | Method and Description |
|---|---|
protected javax.crypto.SecretKey |
engineGenerateKey() |
protected void |
engineInit(java.security.spec.AlgorithmParameterSpec spec,
java.security.SecureRandom random) |
protected void |
engineInit(int keySize,
java.security.SecureRandom random) |
protected void |
engineInit(java.security.SecureRandom random) |
protected void engineInit(java.security.SecureRandom random)
engineInit in class javax.crypto.KeyGeneratorSpiprotected void engineInit(int keySize,
java.security.SecureRandom random)
engineInit in class javax.crypto.KeyGeneratorSpiprotected void engineInit(java.security.spec.AlgorithmParameterSpec spec,
java.security.SecureRandom random)
throws java.security.InvalidAlgorithmParameterException
engineInit in class javax.crypto.KeyGeneratorSpijava.security.InvalidAlgorithmParameterExceptionprotected javax.crypto.SecretKey engineGenerateKey()
engineGenerateKey in class javax.crypto.KeyGeneratorSpi