@Test public void encryptedKeyPemStringToRsaPrivateKeyWithPassword__nullPrivateKeyPemStringInput__throwsIllegalArgumentException() throws Exception { try { PopTokenBuilderUtils.encryptedKeyPemStringToRsaPrivateKey(null, null); fail("Should have thrown IllegalArgumentException"); } catch (Exception ex) { logger.error("Error occurred while executing the test case, error: " + ex.toString(), ex); assertEquals(IllegalArgumentException.class, ex.getClass()); assertEquals("The encryptedPrivateKeyPemString should not be null or empty", ex.getMessage()); } }
public static RSAPrivateKey encryptedKeyPemStringToRsaPrivateKey(String encryptedPrivateKeyPemString, String privateKeyPassword) throws PopPrivateKeyParseException { if (StringUtils.isBlank(encryptedPrivateKeyPemString)) { throw new IllegalArgumentException("The encryptedPrivateKeyPemString should not be null or empty"); } if (StringUtils.isBlank(privateKeyPassword)) { throw new IllegalArgumentException("The privateKeyPassword should not be null or empty"); } try { if (encryptedPrivateKeyPemString.startsWith(PKCS_8_ENCRYPTED_PRIVATE_KEY_PREFIX) && encryptedPrivateKeyPemString.contains(PKCS_8_ENCRYPTED_PRIVATE_KEY_SUFFIX)) { return buildRsaPrivateKey(encryptedPrivateKeyPemString, privateKeyPassword); } else { throw new PopPrivateKeyParseException( "The encryptedPrivateKeyPemString contains unsupported format, only PKCS#8 format is currently supported"); } } catch (PopPrivateKeyParseException ex) { throw ex; } catch (Exception ex) { throw new PopPrivateKeyParseException( "Error occurred while converting encryptedPrivateKeyPemString to RSAPrivateKey, error: " + ex.toString(), ex); } }
PopTokenBuilderUtils { public static RSAPrivateKey encryptedKeyPemStringToRsaPrivateKey(String encryptedPrivateKeyPemString, String privateKeyPassword) throws PopPrivateKeyParseException { if (StringUtils.isBlank(encryptedPrivateKeyPemString)) { throw new IllegalArgumentException("The encryptedPrivateKeyPemString should not be null or empty"); } if (StringUtils.isBlank(privateKeyPassword)) { throw new IllegalArgumentException("The privateKeyPassword should not be null or empty"); } try { if (encryptedPrivateKeyPemString.startsWith(PKCS_8_ENCRYPTED_PRIVATE_KEY_PREFIX) && encryptedPrivateKeyPemString.contains(PKCS_8_ENCRYPTED_PRIVATE_KEY_SUFFIX)) { return buildRsaPrivateKey(encryptedPrivateKeyPemString, privateKeyPassword); } else { throw new PopPrivateKeyParseException( "The encryptedPrivateKeyPemString contains unsupported format, only PKCS#8 format is currently supported"); } } catch (PopPrivateKeyParseException ex) { throw ex; } catch (Exception ex) { throw new PopPrivateKeyParseException( "Error occurred while converting encryptedPrivateKeyPemString to RSAPrivateKey, error: " + ex.toString(), ex); } } }
PopTokenBuilderUtils { public static RSAPrivateKey encryptedKeyPemStringToRsaPrivateKey(String encryptedPrivateKeyPemString, String privateKeyPassword) throws PopPrivateKeyParseException { if (StringUtils.isBlank(encryptedPrivateKeyPemString)) { throw new IllegalArgumentException("The encryptedPrivateKeyPemString should not be null or empty"); } if (StringUtils.isBlank(privateKeyPassword)) { throw new IllegalArgumentException("The privateKeyPassword should not be null or empty"); } try { if (encryptedPrivateKeyPemString.startsWith(PKCS_8_ENCRYPTED_PRIVATE_KEY_PREFIX) && encryptedPrivateKeyPemString.contains(PKCS_8_ENCRYPTED_PRIVATE_KEY_SUFFIX)) { return buildRsaPrivateKey(encryptedPrivateKeyPemString, privateKeyPassword); } else { throw new PopPrivateKeyParseException( "The encryptedPrivateKeyPemString contains unsupported format, only PKCS#8 format is currently supported"); } } catch (PopPrivateKeyParseException ex) { throw ex; } catch (Exception ex) { throw new PopPrivateKeyParseException( "Error occurred while converting encryptedPrivateKeyPemString to RSAPrivateKey, error: " + ex.toString(), ex); } }  }
PopTokenBuilderUtils { public static RSAPrivateKey encryptedKeyPemStringToRsaPrivateKey(String encryptedPrivateKeyPemString, String privateKeyPassword) throws PopPrivateKeyParseException { if (StringUtils.isBlank(encryptedPrivateKeyPemString)) { throw new IllegalArgumentException("The encryptedPrivateKeyPemString should not be null or empty"); } if (StringUtils.isBlank(privateKeyPassword)) { throw new IllegalArgumentException("The privateKeyPassword should not be null or empty"); } try { if (encryptedPrivateKeyPemString.startsWith(PKCS_8_ENCRYPTED_PRIVATE_KEY_PREFIX) && encryptedPrivateKeyPemString.contains(PKCS_8_ENCRYPTED_PRIVATE_KEY_SUFFIX)) { return buildRsaPrivateKey(encryptedPrivateKeyPemString, privateKeyPassword); } else { throw new PopPrivateKeyParseException( "The encryptedPrivateKeyPemString contains unsupported format, only PKCS#8 format is currently supported"); } } catch (PopPrivateKeyParseException ex) { throw ex; } catch (Exception ex) { throw new PopPrivateKeyParseException( "Error occurred while converting encryptedPrivateKeyPemString to RSAPrivateKey, error: " + ex.toString(), ex); } }  static RSAPrivateKey keyPemStringToRsaPrivateKey(String privateKeyPemString); static RSAPrivateKey encryptedKeyPemStringToRsaPrivateKey(String encryptedPrivateKeyPemString, String privateKeyPassword); }
PopTokenBuilderUtils { public static RSAPrivateKey encryptedKeyPemStringToRsaPrivateKey(String encryptedPrivateKeyPemString, String privateKeyPassword) throws PopPrivateKeyParseException { if (StringUtils.isBlank(encryptedPrivateKeyPemString)) { throw new IllegalArgumentException("The encryptedPrivateKeyPemString should not be null or empty"); } if (StringUtils.isBlank(privateKeyPassword)) { throw new IllegalArgumentException("The privateKeyPassword should not be null or empty"); } try { if (encryptedPrivateKeyPemString.startsWith(PKCS_8_ENCRYPTED_PRIVATE_KEY_PREFIX) && encryptedPrivateKeyPemString.contains(PKCS_8_ENCRYPTED_PRIVATE_KEY_SUFFIX)) { return buildRsaPrivateKey(encryptedPrivateKeyPemString, privateKeyPassword); } else { throw new PopPrivateKeyParseException( "The encryptedPrivateKeyPemString contains unsupported format, only PKCS#8 format is currently supported"); } } catch (PopPrivateKeyParseException ex) { throw ex; } catch (Exception ex) { throw new PopPrivateKeyParseException( "Error occurred while converting encryptedPrivateKeyPemString to RSAPrivateKey, error: " + ex.toString(), ex); } }  static RSAPrivateKey keyPemStringToRsaPrivateKey(String privateKeyPemString); static RSAPrivateKey encryptedKeyPemStringToRsaPrivateKey(String encryptedPrivateKeyPemString, String privateKeyPassword);  }