import com.marcozanon.macaco.json.MInvalidJsonValueException;
import com.marcozanon.macaco.json.MJsonObject;
import com.marcozanon.macaco.json.MJsonString;
+import com.marcozanon.macaco.text.MText;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
/* License generation. */
public static void generateFullLicense(Path privateKeyFile, Path licenseSkeletonFile, Path fullLicenseFile) throws MLicensingException {
+ if (null == privateKeyFile) {
+ throw new IllegalArgumentException("Invalid 'privateKeyFile': null.");
+ }
+ if (null == licenseSkeletonFile) {
+ throw new IllegalArgumentException("Invalid 'licenseSkeletonFile': null.");
+ }
+ if (null == fullLicenseFile) {
+ throw new IllegalArgumentException("Invalid 'fullLicenseFile': null.");
+ }
+ //
try {
String privateKeyPemString = new String(Files.readAllBytes(privateKeyFile), MConstants.DEFAULT_CHARSET);
String licenseSkeletonJsonString = new String(Files.readAllBytes(licenseSkeletonFile), MConstants.DEFAULT_CHARSET);
}
public static MJsonObject generateFullLicense(String privateKeyPemString, String licenseSkeletonJsonString) throws MLicensingException {
+ if (MText.isBlank(privateKeyPemString)) {
+ throw new IllegalArgumentException("Invalid 'privateKeyPemString': null or empty.");
+ }
+ if (MText.isBlank(licenseSkeletonJsonString)) {
+ throw new IllegalArgumentException("Invalid 'licenseSkeletonJsonString': null or empty.");
+ }
+ //
try {
byte[] privateKeyContent = Base64.getDecoder().decode(privateKeyPemString.replace("-----BEGIN PRIVATE KEY-----", "").replaceAll("\\R", "").replace("-----END PRIVATE KEY-----", ""));
RSAPrivateKey privateKey = (RSAPrivateKey)KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(privateKeyContent));
/* License verification. */
public static MJsonObject verifyFullLicense(Path publicKeyFile, Path fullLicenseFile) throws MLicensingException {
+ if (null == publicKeyFile) {
+ throw new IllegalArgumentException("Invalid 'publicKeyFile': null.");
+ }
+ if (null == fullLicenseFile) {
+ throw new IllegalArgumentException("Invalid 'fullLicenseFile': null.");
+ }
+ //
try {
String publicKeyPemString = new String(Files.readAllBytes(publicKeyFile), MConstants.DEFAULT_CHARSET);
String fullLicenseJsonString = new String(Files.readAllBytes(fullLicenseFile), MConstants.DEFAULT_CHARSET);
}
public static MJsonObject verifyFullLicense(String publicKeyPemString, String fullLicenseJsonString) throws MLicensingException {
+ if (MText.isBlank(publicKeyPemString)) {
+ throw new IllegalArgumentException("Invalid 'publicKeyPemString': null or empty.");
+ }
+ if (MText.isBlank(fullLicenseJsonString)) {
+ throw new IllegalArgumentException("Invalid 'fullLicenseJsonString': null or empty.");
+ }
+ //
try {
byte[] publicKeyContent = Base64.getDecoder().decode(publicKeyPemString.replace("-----BEGIN PUBLIC KEY-----", "").replaceAll("\\R", "").replace("-----END PUBLIC KEY-----", ""));
RSAPublicKey publicKey = (RSAPublicKey)KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKeyContent));