Class IdentifierGenerator

java.lang.Object
io.getlime.security.powerauth.crypto.lib.generator.IdentifierGenerator

public class IdentifierGenerator extends Object
Generator of identifiers used in PowerAuth protocol.
Author:
Petr Dvorak, petr.dvorak@wultra.com, Roman Strobl, roman.strobl@wultra.com
  • Constructor Details

    • IdentifierGenerator

      public IdentifierGenerator()
  • Method Details

    • generateActivationId

      public String generateActivationId()
      Generate a new random activation ID - a UUID level 4 instance.
      Returns:
      New pseudo-random activation ID.
    • generateActivationCode

      public String generateActivationCode() throws CryptoProviderException
      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

      public String generateActivationCode(byte[] randomBytes) throws GenericCryptoException
      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

      public boolean validateActivationCode(String activationCode)
      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

      Generate 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

      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.