@Test public void testRsaEncryption() { String keystorePath = "src/test/resources/.ssh/keystore.p12"; String keystorePass = "j4c"; String secret = "some secret to encrypt"; String certAlias = "1"; String[] args = new String[] {"rsa", keystorePath, keystorePass, certAlias, secret}; PrivateKey pk = KeyConfig.keystoreBuilder() .keystore(Resource.create(Paths.get(keystorePath))) .keyAlias("1") .keystorePassphrase(keystorePass.toCharArray()) .build() .privateKey().orElseThrow(AssertionError::new); Main.EncryptionCliProcessor ecp = new Main.EncryptionCliProcessor(); ecp.parse(args); assertEquals(Main.Algorithm.rsa, ecp.getAlgorithm()); assertNotNull(ecp.getPublicKey()); assertEquals(secret, ecp.getSecret()); String encrypted = ecp.encrypt(); assertAll(() -> assertThat("Encrypted string should start with rsa prefix: " + encrypted, encrypted.startsWith(EncryptionFilter.PREFIX_RSA)), () -> assertThat("Encrypted string should end with \"}\": " + encrypted, encrypted.endsWith("}"))); String base64 = encrypted.substring(EncryptionFilter.PREFIX_RSA.length(), encrypted.length() - 1); Base64.getDecoder().decode(base64); String orig = EncryptionUtil.decryptRsa(pk, base64); assertEquals(secret, orig); Main.main(args); }
private Main() { throw new IllegalStateException("Main class"); }
Main { private Main() { throw new IllegalStateException("Main class"); } }
Main { private Main() { throw new IllegalStateException("Main class"); } private  Main(); }
Main { private Main() { throw new IllegalStateException("Main class"); } private  Main(); static void main(String[] args); }
Main { private Main() { throw new IllegalStateException("Main class"); } private  Main(); static void main(String[] args);  }