public class License extends Object
You can use a License object for two purposes:
| Modifier and Type | Field and Description |
|---|---|
protected Properties |
licenseProperties |
| Constructor and Description |
|---|
License() |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
calculatePublicKeyRingDigest()
Calculate the SHA512 digest of the public key ring that is used to decode
the license.
|
void |
dumpLicense(File file)
Dump the license as clear text into the file.
|
void |
dumpLicense(OutputStream os)
Dump the license as clear text into the output stream.
|
void |
dumpLicense(String fileName)
Dump the license as clear text into a file.
|
String |
dumpPublicKeyRingDigest()
Dump the public key ring digest as a Java code fragment.
|
String |
encodeLicense(String keyPassPhraseString)
Encode the currently loaded/created license.
|
static String |
fromResource(String resourceName) |
Long |
getDecodeKeyId()
Get the key id that was used to decode the license.
|
String |
getFeature(String key)
Get a license feature.
|
String |
getLicenseString()
Get the license as clear text.
|
boolean |
isVerified()
Check if the license was verified.
|
License |
loadKey(File fin,
String userId)
Load the secret key to be used to encrypt a license.
|
License |
loadKey(InputStream inputStream,
String userId)
Load the secret key to be used to encrypt the license.
|
License |
loadKey(String fn,
String keyId)
Load the secret key to be used to encrypt a license.
|
License |
loadKeyRing(File file,
byte[] digest)
Load a key ring from a file.
|
License |
loadKeyRing(InputStream in,
byte[] digest)
Load a key ring from an input stream that can be used to verify a
license.
|
License |
loadKeyRing(String fileName,
byte[] digest)
Load a key ring from a file.
|
void |
loadKeyRingFromResource(String resourceName,
byte[] digest)
Load a key ring from a resource file (a file that is packaged into the
JAR file).
|
void |
setFeature(String key,
String value)
Set a license feature.
|
void |
setHashAlgorithm(int hashAlgorithm)
Set the hash algorithm to use to sign the license.
|
License |
setLicense(File file)
Set the license values from a clear text file.
|
void |
setLicense(InputStream is)
Set the license values from an input stream.
|
void |
setLicense(String licenseString)
Set the license from clear text format.
|
void |
setLicenseEncoded(File file)
Open an encoded license file.
|
void |
setLicenseEncoded(InputStream inputStream)
Open an encoded license from input stream, decode and load it.
|
License |
setLicenseEncoded(String licenseStringEncoded)
Open an encoded license from the string literal.
|
void |
setLicenseEncodedFromFile(File file)
Deprecated.
|
License |
setLicenseEncodedFromFile(String fileName)
Open an encoded license from a file.
|
License |
setLicenseEncodedFromResource(String resourceName)
Open an encoded license from a Java resource.
|
protected Properties licenseProperties
public void setFeature(String key, String value)
key - the name of the featurevalue - the string value of the featurepublic String getFeature(String key)
key - the name of the feature.public void setLicense(InputStream is) throws IOException
is - the input stream to read the properties values fromIOException - when the input stream can not be readpublic License setLicense(File file) throws IOException
file - the file to read the license data.thisIOException - when the file can not be readpublic void setLicense(String licenseString) throws IOException
licenseString - the properties content.IOException - when the string is badly formatter and therefore the
license can not be loaded from the stringpublic String getLicenseString()
public void dumpLicense(String fileName) throws IOException
fileName - the name of the file to dump the license into.IOException - when there is an error writing the filepublic void dumpLicense(File file) throws IOException
file - the file to write the license text.IOException - when there is an error writing the filepublic void dumpLicense(OutputStream os) throws IOException
os - the output stream.IOExceptionpublic boolean isVerified()
public void setHashAlgorithm(int hashAlgorithm)
Call to this method is needed only when encoding license and only when the default algorithm is not appropriate for some reason or if the caller wants to ensure that the default algorithm is used even when a later version of this library is used.
The default algorithm may change in future versions of this class. Note that the default algorithm was SHA1 prior to version 1.0.4
hashAlgorithm - the hash algorithm, a constant from the
class org.bouncycastle.openpgp.PGPUtil. For more information on
this class visit Bouncy Castlepublic License loadKey(String fn, String keyId) throws IOException, org.bouncycastle.openpgp.PGPException
fn - the name of the file that contains the key rings.keyId - the id of the key to be used.IOExceptionorg.bouncycastle.openpgp.PGPExceptionpublic void loadKeyRingFromResource(String resourceName, byte[] digest) throws IOException
loadKeyRing(InputStream in, byte[] digest).resourceName - the name of the file inside the JAR file with full
path.digest - the SHA512 digest of the key ring.IOExceptionpublic License loadKeyRing(String fileName, byte[] digest) throws FileNotFoundException, IOException
loadKeyRing(InputStream in, byte[] digest).fileName - the name of the filedigest - the SHA512 digest of the ringIOExceptionFileNotFoundExceptionpublic License loadKeyRing(File file, byte[] digest) throws FileNotFoundException, IOException
loadKeyRing(InputStream in, byte[] digest).file - the filedigest - the SHA512 digest of the ringIOExceptionFileNotFoundExceptionpublic License loadKeyRing(InputStream in, byte[] digest) throws IOException
in - the input stream where the key ring comes from.digest - the digest of the key ring. If this parameter is
null then the key ring is loaded no matter of its checksum.IOExceptionIllegalArgumentException - when the digest does not match the
supplied digest. This means that the JAR file containing the key ring was
tampered and the key ring is not the same as the one packaged by the
developer. In this case using the key ring is useless to check the
authenticity of the license and because of this the key ring is not
loaded in such a case.public byte[] calculatePublicKeyRingDigest()
public String dumpPublicKeyRingDigest()
loadKeyRing to
protect the code from key ring replacement.public License loadKey(File fin, String userId) throws IOException, org.bouncycastle.openpgp.PGPException
loadKey(InputStream in, String userId).fin - the file that contains the key ring.userId - the user id of the key to be used.IOExceptionorg.bouncycastle.openpgp.PGPExceptionpublic License loadKey(InputStream inputStream, String userId) throws IOException, org.bouncycastle.openpgp.PGPException
inputStream - input stream of the file containing the key ringsuserId - the user id of the key. If this parameter is null
then the first key on the key ring appropriate to sign will be used.IOExceptionorg.bouncycastle.openpgp.PGPExceptionpublic String encodeLicense(String keyPassPhraseString) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, org.bouncycastle.openpgp.PGPException, SignatureException
keyPassPhraseString - the pass phrase to the signing key that was
loaded.IOExceptionNoSuchAlgorithmExceptionNoSuchProviderExceptionorg.bouncycastle.openpgp.PGPExceptionSignatureExceptionpublic License setLicenseEncoded(String licenseStringEncoded) throws UnsupportedEncodingException, IOException, org.bouncycastle.openpgp.PGPException
licenseStringEncoded - the license encoded in string format.org.bouncycastle.openpgp.PGPExceptionIOExceptionUnsupportedEncodingExceptionpublic License setLicenseEncodedFromResource(String resourceName) throws IOException, org.bouncycastle.openpgp.PGPException
resourceName - the name of the resource that contains the license.org.bouncycastle.openpgp.PGPExceptionIOExceptionpublic License setLicenseEncodedFromFile(String fileName) throws FileNotFoundException, IOException, org.bouncycastle.openpgp.PGPException
fileName - the name of the file containing the encoded license.org.bouncycastle.openpgp.PGPExceptionIOExceptionFileNotFoundException@Deprecated public void setLicenseEncodedFromFile(File file) throws FileNotFoundException, IOException, org.bouncycastle.openpgp.PGPException
setLicenseEncoded(File file).file - org.bouncycastle.openpgp.PGPExceptionIOExceptionFileNotFoundExceptionpublic void setLicenseEncoded(File file) throws FileNotFoundException, IOException, org.bouncycastle.openpgp.PGPException
file - the file where the encoded license is.org.bouncycastle.openpgp.PGPExceptionIOExceptionFileNotFoundExceptionpublic Long getDecodeKeyId()
The key used to generate commercial licenses is stored in a bunker, deep down under the ground between steel walls.
In such a situation the protected program will not accept a commercial non expiring license (that could have been stolen) signed by the demo license key.
public void setLicenseEncoded(InputStream inputStream) throws IOException, org.bouncycastle.openpgp.PGPException
isVerified() will return false.
Otherwise the license is loaded and can be used.
inputStream - IOExceptionorg.bouncycastle.openpgp.PGPExceptionCopyright © 2015. All Rights Reserved.