Class LicenseKeyPair.Create

  • Enclosing class:
    LicenseKeyPair

    public static class LicenseKeyPair.Create
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Create()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static LicenseKeyPair from​(byte[] privateEncoded, byte[] publicEncoded)
      Create a new LicenseKeyPair from the public and the private key pairs.
      static LicenseKeyPair from​(byte[] encoded, int type)
      Create a new LicenseKeyPair that contains only one of the keys, either the private or the public.
      static LicenseKeyPair from​(java.lang.String cipher, int size)
      Create a new key pair using the algorithm and the size for the key.
      static LicenseKeyPair from​(java.security.KeyPair keyPair, java.lang.String cipher)
      Create a new key pair.
      static LicenseKeyPair from​(java.security.PublicKey publicKey, java.security.PrivateKey privateKey, java.lang.String cipher)
      Create a new key pair.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Create

        public Create()
    • Method Detail

      • from

        public static LicenseKeyPair from​(java.security.PublicKey publicKey,
                                          java.security.PrivateKey privateKey,
                                          java.lang.String cipher)
        Create a new key pair.
        Parameters:
        publicKey - to be stored in the object
        privateKey - to be stored in the object
        cipher - to be stored in the object
        Returns:
        the new object
      • from

        public static LicenseKeyPair from​(java.security.KeyPair keyPair,
                                          java.lang.String cipher)
        Create a new key pair.
        Parameters:
        keyPair - to be stored in the object
        cipher - to be stored in the object
        Returns:
        the new object
      • from

        public static LicenseKeyPair from​(java.lang.String cipher,
                                          int size)
                                   throws java.security.NoSuchAlgorithmException
        Create a new key pair using the algorithm and the size for the key. The cipher transformation may optionally contain the mode and the padding as algorithm/mode/padding. Note that the mode and the padding is not needed for the key generation. Nevertheless these are also stored in the generated LicenseKeyPair and will be used to sign/verify the license.

        It is recommended to use the full cipher. Using only the algorithm will let the encryption provider to selects its own favoutire mode and padding. In this case it may happen that the signing and the verification happening in different environments may use different providers that are not compatible and an otherwise completely perfect license will not verify.

        Parameters:
        cipher - the cipher string
        size - the size of the key to generate
        Returns:
        the new create LicenseKeyPair
        Throws:
        java.security.NoSuchAlgorithmException - when the cipher specifies an algorithm that is not known by the encryption provider
      • from

        public static LicenseKeyPair from​(byte[] encoded,
                                          int type)
                                   throws java.security.NoSuchAlgorithmException,
                                          java.security.spec.InvalidKeySpecException
        Create a new LicenseKeyPair that contains only one of the keys, either the private or the public. The key is provided in binary format as a byte array.
        Parameters:
        encoded - the key encoded as byte array. This is the format that contains the algorithm at the start of the byte array as zero byte terminated string.
        type - either 1 for public key specification or 2 for private key specification. These commands are defined in the JDK in the Modifier class as Modifier.PUBLIC and Modifier.PRIVATE.
        Returns:
        the newly created LicenseKeyPair
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm in the encoded key is not implemented by the actual encryption provider
        java.security.spec.InvalidKeySpecException - if the bytes of the key are garbage and cannot be decoded by the actual encryption provider.
      • from

        public static LicenseKeyPair from​(byte[] privateEncoded,
                                          byte[] publicEncoded)
                                   throws java.security.NoSuchAlgorithmException,
                                          java.security.spec.InvalidKeySpecException
        Create a new LicenseKeyPair from the public and the private key pairs. The method does not check that the encoded cipher specification at the start of the keys are the same or not. They are supposed to be the same. There is also no check that the private and the public key are a pair.
        Parameters:
        privateEncoded - the private key encoded including the cipher specification with a zero byte terminated at the start of the byte array
        publicEncoded - the public key encoded including the cipher specification with a zero byte terminated at the start of the byte array
        Returns:
        the newly created LicenseKeyPair
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm in the encoded key is not implemented by the actual encryption provider
        java.security.spec.InvalidKeySpecException - if the bytes of the key are garbage and cannot be decoded by the actual encryption provider.