Class PGPHelper
java.lang.Object
org.jpos.util.PGPHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intVerifies the licensee file's signature, parses its metadata, and returns a packed status code combining expiration, fingerprint match, instance count, and revocation flags.static booleanVerifies the signature on the bundled licensee file using the embedded jPOS public key.static byte[]decrypt(byte[] encrypted, InputStream keyIn, char[] password) decrypt the passed in message streamstatic byte[]decrypt the passed in message streamstatic byte[]encrypt(byte[] clearData, InputStream keyRing, String fileName, boolean withIntegrityCheck, boolean armor, String... ids) Simple PGP encryptor between byte[].static byte[]encrypt(byte[] clearData, String keyRing, String fileName, boolean withIntegrityCheck, boolean armor, String... ids) Simple PGP encryptor between byte[].static LicenseReturns the parsed jPOSLicenseextracted from the licensee resource.static StringReturns the licensee file contents as a UTF-8 string with two leading blank lines.static StringReturns the SHA hex hash of the licensee text as produced bygetLicensee().static StringReturns the verified clear-text license payload.static intnode()Returns the resolved Q2 node number used during license validation.
-
Constructor Details
-
PGPHelper
public PGPHelper()Utility class; instances carry no state.
-
-
Method Details
-
checkSignature
Verifies the signature on the bundled licensee file using the embedded jPOS public key.- Returns:
trueif the signature verifies,falseotherwise (including any error)
-
checkLicense
Verifies the licensee file's signature, parses its metadata, and returns a packed status code combining expiration, fingerprint match, instance count, and revocation flags.- Returns:
- packed status code; bits encode validity, expiration, fingerprint match, revocation, and the configured instance count
-
getVerifiedLicenseText
Returns the verified clear-text license payload.The returned value is the text covered by the clear-text PGP signature, not the armored license block. If the bundled or configured license cannot be signature-verified, or if
checkLicense()reports an unacceptable status, this method returnsnull.Status bit
0x10000(license not bound to this system hash, used by the Community Edition license) is considered acceptable. Critical status bits0xE0000are not.- Returns:
- verified clear-text license payload, or
null - Throws:
IOException- if the license stream cannot be read
-
getLicensee
Returns the licensee file contents as a UTF-8 string with two leading blank lines.- Returns:
- the licensee text, or empty if the licensee resource is unavailable
- Throws:
IOException- if reading the licensee stream fails
-
getLicenseeHash
Returns the SHA hex hash of the licensee text as produced bygetLicensee().- Returns:
- the hex-encoded hash
- Throws:
IOException- if the licensee stream cannot be readNoSuchAlgorithmException- if the configured digest is not available
-
node
Returns the resolved Q2 node number used during license validation.- Returns:
- the Q2 node number, or 0 if it could not be resolved
-
encrypt
public static byte[] encrypt(byte[] clearData, InputStream keyRing, String fileName, boolean withIntegrityCheck, boolean armor, String... ids) throws IOException, org.bouncycastle.openpgp.PGPException, NoSuchProviderException, NoSuchAlgorithmException Simple PGP encryptor between byte[].- Parameters:
clearData- The test to be encryptedkeyRing- public key ring input streamfileName- File name. This is used in the Literal Data Packet (tag 11) which is really only important if the data is to be related to a file to be recovered later. Because this routine does not know the source of the information, the caller can set something here for file name use that will be carried. If this routine is being used to encrypt SOAP MIME bodies, for example, use the file name from the MIME type, if applicable. Or anything else appropriate.withIntegrityCheck- true if an integrity packet is to be includedarmor- true for ascii armorids- destination ids- Returns:
- encrypted data.
- Throws:
IOException- if readingkeyRingor writing the encrypted output failsorg.bouncycastle.openpgp.PGPException- if a PGP-level error occurs while building the messageNoSuchProviderException- if theBCprovider is not registeredNoSuchAlgorithmException- if the requested cipher algorithm is unavailable
-
encrypt
public static byte[] encrypt(byte[] clearData, String keyRing, String fileName, boolean withIntegrityCheck, boolean armor, String... ids) throws IOException, org.bouncycastle.openpgp.PGPException, NoSuchProviderException, NoSuchAlgorithmException Simple PGP encryptor between byte[].- Parameters:
clearData- The test to be encryptedkeyRing- public key ring input streamfileName- File name. This is used in the Literal Data Packet (tag 11) which is really only important if the data is to be related to a file to be recovered later. Because this routine does not know the source of the information, the caller can set something here for file name use that will be carried. If this routine is being used to encrypt SOAP MIME bodies, for example, use the file name from the MIME type, if applicable. Or anything else appropriate.withIntegrityCheck- true if an integrity packet is to be includedarmor- true for ascii armorids- destination ids- Returns:
- encrypted data.
- Throws:
IOException- ifkeyRingcannot be opened or the encrypted output cannot be writtenorg.bouncycastle.openpgp.PGPException- if a PGP-level error occurs while building the messageNoSuchProviderException- if theBCprovider is not registeredNoSuchAlgorithmException- if the requested cipher algorithm is unavailable
-
decrypt
public static byte[] decrypt(byte[] encrypted, InputStream keyIn, char[] password) throws IOException, org.bouncycastle.openpgp.PGPException, NoSuchProviderException decrypt the passed in message stream- Parameters:
encrypted- The message to be decrypted.keyIn- secret key ring input streampassword- Pass phrase (key)- Returns:
- Clear text as a byte array. I18N considerations are not handled by this routine
- Throws:
IOException- ifkeyInor the encrypted payload cannot be readorg.bouncycastle.openpgp.PGPException- if a PGP-level error occurs while decryptingNoSuchProviderException- if theBCprovider is not registered
-
decrypt
public static byte[] decrypt(byte[] encrypted, String keyIn, char[] password) throws IOException, org.bouncycastle.openpgp.PGPException, NoSuchProviderException decrypt the passed in message stream- Parameters:
encrypted- The message to be decrypted.keyIn- path to the secret key ring filepassword- Pass phrase (key)- Returns:
- Clear text as a byte array. I18N considerations are not handled by this routine
- Throws:
IOException- if the key file or encrypted payload cannot be readorg.bouncycastle.openpgp.PGPException- if a PGP-level error occurs while decryptingNoSuchProviderException- if theBCprovider is not registered
-
getLicense
Returns the parsed jPOSLicenseextracted from the licensee resource.- Returns:
- the current license, including text and status flags
- Throws:
IOException- if the licensee stream cannot be read
-