Package javax0.license3j.crypto
Class LicenseKeyPair.Create
- java.lang.Object
-
- javax0.license3j.crypto.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 newLicenseKeyPair
from the public and the private key pairs.static LicenseKeyPair
from(byte[] encoded, int type)
Create a newLicenseKeyPair
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.
-
-
-
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 objectprivateKey
- to be stored in the objectcipher
- 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 objectcipher
- 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 asalgorithm/mode/padding
. Note that the mode and the padding is not needed for the key generation. Nevertheless these are also stored in the generatedLicenseKeyPair
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 stringsize
- the size of the key to generate- Returns:
- the new create
LicenseKeyPair
- Throws:
java.security.NoSuchAlgorithmException
- when thecipher
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 newLicenseKeyPair
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 theModifier
class asModifier.PUBLIC
andModifier.PRIVATE
.- Returns:
- the newly created
LicenseKeyPair
- Throws:
java.security.NoSuchAlgorithmException
- if the algorithm in the encoded key is not implemented by the actual encryption providerjava.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 newLicenseKeyPair
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 arraypublicEncoded
- 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 providerjava.security.spec.InvalidKeySpecException
- if the bytes of the key are garbage and cannot be decoded by the actual encryption provider.
-
-