Class IdentifierGenerator
java.lang.Object
io.getlime.security.powerauth.crypto.lib.generator.IdentifierGenerator
Generator of identifiers used in PowerAuth protocol.
- Author:
- Petr Dvorak, petr.dvorak@wultra.com, Roman Strobl, roman.strobl@wultra.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionderiveRecoveryCode(SecretKey secretKey, RecoverySeed seed) Derive recovery code and PUKs for given secret key and seed information.Generate version 3.0 or higher activation code.generateActivationCode(byte[] randomBytes) Generate version 3.0 or higher activation code using provided random bytes.Generate a new random activation ID - a UUID level 4 instance.Generate recovery code and PUK.generateRecoveryCode(SecretKey secretKey, int pukCount, boolean exportSeed) Generate recovery code and PUKs for given secret key, return optional seed information.booleanvalidateActivationCode(String activationCode) Validate activation code using CRC-16 checksum.
-
Constructor Details
-
IdentifierGenerator
public IdentifierGenerator()
-
-
Method Details
-
generateActivationId
Generate a new random activation ID - a UUID level 4 instance.- Returns:
- New pseudo-random activation ID.
-
generateActivationCode
Generate version 3.0 or higher activation code. The format of activation code is "ABCDE-FGHIJ-KLMNO-PQRST".Activation code construction:
- Generate 10 random bytes.
- Calculate CRC-16 from that 10 bytes.
- Append CRC-16 (2 bytes) in big endian order at the end of random bytes.
- Generate Base32 representation from these 12 bytes, without padding characters.
- Split Base32 string into 4 groups, each one contains 5 characters. Use "-" as separator.
- Returns:
- Generated activation code.
- Throws:
CryptoProviderException- In case key cryptography provider is incorrectly initialized.
-
generateActivationCode
Generate version 3.0 or higher activation code using provided random bytes. The format of activation code is "ABCDE-FGHIJ-KLMNO-PQRST".Activation code construction:
- Use provided 10 random bytes.
- Calculate CRC-16 from that 10 bytes.
- Append CRC-16 (2 bytes) in big endian order at the end of random bytes.
- Generate Base32 representation from these 12 bytes, without padding characters.
- Split Base32 string into 4 groups, each one contains 5 characters. Use "-" as separator.
- Parameters:
randomBytes- Random bytes to use when generating the activation code.- Returns:
- Generated activation code.
- Throws:
GenericCryptoException- In case generating activation code fails.
-
validateActivationCode
Validate activation code using CRC-16 checksum. The expected format of activation code is "ABCDE-FGHIJ-KLMNO-PQRST".- Parameters:
activationCode- Activation code.- Returns:
- Whether activation code is correct.
-
generateRecoveryCode
public RecoveryInfo generateRecoveryCode() throws GenericCryptoException, CryptoProviderException, InvalidKeyExceptionGenerate recovery code and PUK.- Returns:
- Recovery code and PUK.
- Throws:
GenericCryptoException- In case of any cryptography error.CryptoProviderException- In case cryptography provider is incorrectly initialized.InvalidKeyException- In case key is invalid.
-
generateRecoveryCode
public RecoveryInfo generateRecoveryCode(SecretKey secretKey, int pukCount, boolean exportSeed) throws GenericCryptoException, CryptoProviderException, InvalidKeyException Generate recovery code and PUKs for given secret key, return optional seed information.- Parameters:
secretKey- Secret key to use for derivation of recovery code and PUK.pukCount- Number of PUKs to generate.exportSeed- Whether to export seed information.- Returns:
- Recovery code, PUKs and optional seed information.
- Throws:
GenericCryptoException- In case of any cryptography error.CryptoProviderException- In case cryptography provider is incorrectly initialized.InvalidKeyException- In case key is invalid.
-
deriveRecoveryCode
public RecoveryInfo deriveRecoveryCode(SecretKey secretKey, RecoverySeed seed) throws GenericCryptoException, CryptoProviderException, InvalidKeyException Derive recovery code and PUKs for given secret key and seed information.- Parameters:
secretKey- Secret key to use for derivation of recovery code and PUKs.seed- Seed information containing nonce and puk derivation indexes.- Returns:
- Derived recovery code and PUKs.
- Throws:
GenericCryptoException- In case of any cryptography error.CryptoProviderException- In case cryptography provider is incorrectly initialized.InvalidKeyException- In case key is invalid.
-