license4j |
License |
LicenseManager |
LicenseNotFoundException |
LicenseUtil |
| |
com.smardec.license4j
Class LicenseManager
java.lang.Object
|
+--com.smardec.license4j.LicenseManager
- public final class LicenseManager
- extends java.lang.Object
The main class for managing licenses.
Method Summary |
static java.lang.String |
generateStringKey(int length,
java.lang.String secret)
The method generates string key that can later be checked for validity by isStringKeyValid(String,String). |
static boolean |
isSerializeStrings()
Indicates whether String feature values
will be stored in the license in the serialized form. |
static boolean |
isStringKeyValid(java.lang.String key,
java.lang.String secret)
Validates string key generated by generateStringKey(int,String). |
static boolean |
isValid(License license)
Indicates whether the license is valid. |
static License |
loadLicense(java.io.InputStream stream)
Loads license from the specified InputStream . |
static License |
loadLicense(java.lang.String filename)
Loads license from the specified file. |
static void |
saveLicense(License license,
java.lang.String filename)
Saves the license to the specified file. |
static void |
saveLicense(License license,
java.io.Writer writer)
Saves the license to the specified Writer . |
static void |
setPrivateKey(java.lang.String key)
Sets private key. |
static void |
setPublicKey(java.lang.String key)
Sets public key. |
static void |
setSerializeStrings(boolean serializeStrings)
Specifies whether String feature values
will be stored in the license in the serialized form. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
isSerializeStrings
public static boolean isSerializeStrings()
- Indicates whether
String feature values
will be stored in the license in the serialized form.
If true than String objects will be serialized.
The default is false .
- Returns:
true if String objects will be serialized,
false otherwise. The default is false .
setSerializeStrings
public static void setSerializeStrings(boolean serializeStrings)
- Specifies whether
String feature values
will be stored in the license in the serialized form.
If true than String objects will be serialized.
The default is false .
- Parameters:
- serializeStrings -
true if String objects should be serialized,
false otherwise. The default is false
setPrivateKey
public static void setPrivateKey(java.lang.String key)
- Sets private key. Private key is needed only to create licenses.
- Parameters:
- key - private key
setPublicKey
public static void setPublicKey(java.lang.String key)
- Sets public key. Public key is needed only to validate licenses.
- Parameters:
- key - public key
loadLicense
public static License loadLicense(java.lang.String filename)
throws LicenseNotFoundException
- Loads license from the specified file.
- Parameters:
- filename - name of the license file
- Returns:
License object.
- Throws:
- LicenseNotFoundException - if the license cannot be read
loadLicense
public static License loadLicense(java.io.InputStream stream)
throws LicenseNotFoundException
- Loads license from the specified
InputStream .
- Parameters:
- stream -
InputStream that contains license information
- Returns:
License object.
- Throws:
- LicenseNotFoundException - if the license cannot be read
saveLicense
public static void saveLicense(License license,
java.lang.String filename)
throws java.security.GeneralSecurityException,
java.lang.IllegalArgumentException,
java.io.IOException
- Saves the license to the specified file.
- Parameters:
- license -
License object to write- filename - name of the file
- Throws:
- java.security.GeneralSecurityException - if private key is not initialized by setPrivateKey(String)
- java.lang.IllegalArgumentException - if license has no features
- java.io.IOException - if the specified file exists but is a directory rather
than a regular file, does not exist but cannot be
created, or cannot be opened for any other reason
saveLicense
public static void saveLicense(License license,
java.io.Writer writer)
throws java.security.GeneralSecurityException,
java.lang.IllegalArgumentException,
java.io.IOException
- Saves the license to the specified
Writer .
Note that Writer.close() method is not invoked after writing the license.
- Parameters:
- license -
License object to write- writer -
Writer object
- Throws:
- java.security.GeneralSecurityException - if private key is not initialized by setPrivateKey(String)
- java.lang.IllegalArgumentException - if license has no features
- java.io.IOException - if an I/O error occurs
isValid
public static boolean isValid(License license)
throws java.security.GeneralSecurityException
- Indicates whether the license is valid.
- Parameters:
- license - license to check
- Returns:
true if the license is valid,
false otherwise.
- Throws:
- java.security.GeneralSecurityException - if public key is not initialized by setPublicKey(String)
generateStringKey
public static java.lang.String generateStringKey(int length,
java.lang.String secret)
- The method generates string key that can later be checked for validity by isStringKeyValid(String,String).
- Parameters:
- length - the desired length of the key in symbols, should be even number greater than
8 - secret - secret string used to generate and validate keys (your passphrase)
- Returns:
- generated key, always has even length
isStringKeyValid
public static boolean isStringKeyValid(java.lang.String key,
java.lang.String secret)
- Validates string key generated by generateStringKey(int,String).
- Parameters:
- key - the key
- secret - secret string used to generate and validate keys (your passphrase)
- Returns:
true if the key is valid, false otherwise
|
|
|