public EncryptedPasswordAndPrivateKey build() { return new EncryptedPasswordAndPrivateKey(encryptedPassword, privateKey); }
public Builder toBuilder() { return builder().fromEncryptedPasswordAndPrivateKey(this); }
public Builder fromEncryptedPasswordAndPrivateKey(EncryptedPasswordAndPrivateKey in) { return encryptedPassword(in.getEncryptedPassword()) .privateKey(in.getPrivateKey()); } }
public Builder fromEncryptedPasswordAndPrivateKey(EncryptedPasswordAndPrivateKey in) { return encryptedPassword(in.getEncryptedPassword()) .privateKey(in.getPrivateKey()); } }
public EncryptedPasswordAndPrivateKey build() { return new EncryptedPasswordAndPrivateKey(encryptedPassword, privateKey); }
public Builder toBuilder() { return builder().fromEncryptedPasswordAndPrivateKey(this); }
public Builder fromEncryptedPasswordAndPrivateKey(EncryptedPasswordAndPrivateKey in) { return encryptedPassword(in.getEncryptedPassword()) .privateKey(in.getPrivateKey()); } }
public EncryptedPasswordAndPrivateKey build() { return new EncryptedPasswordAndPrivateKey(encryptedPassword, privateKey); }
public Builder toBuilder() { return builder().fromEncryptedPasswordAndPrivateKey(this); }
@Override public LoginCredentials apply(@Nullable EncryptedPasswordAndPrivateKey dataAndKey) { if (dataAndKey == null) return null; try { KeySpec keySpec = Pems.privateKeySpec(dataAndKey.getPrivateKey()); KeyFactory kf = crypto.rsaKeyFactory(); PrivateKey privKey = kf.generatePrivate(keySpec); Cipher cipher = crypto.cipher("RSA"); cipher.init(Cipher.DECRYPT_MODE, privKey); byte[] cipherText = base64().decode(whitespace.matcher(dataAndKey.getEncryptedPassword()).replaceAll("")); byte[] plainText = cipher.doFinal(cipherText); String password = new String(plainText, UTF_8); return LoginCredentials.builder() .user("Administrator") .password(password) .noPrivateKey() .build(); } catch (Exception e) { throw Throwables.propagate(e); } } }
@Test public void testApply() throws Exception { WindowsLoginCredentialsFromEncryptedData f = new WindowsLoginCredentialsFromEncryptedData(new JCECrypto()); LoginCredentials credentials = f.apply(new EncryptedPasswordAndPrivateKey(ENCRYPTED_PASSWORD, PRIVATE_KEY)); assertEquals(credentials.getUser(), "Administrator"); assertEquals(credentials.getPassword(), "u4.y9mb;nR."); assertFalse(credentials.getOptionalPrivateKey().isPresent()); } }
EncryptedPasswordAndPrivateKey.builder().encryptedPassword(actual).privateKey(privateKey).build()).getPassword(), "bX7vvptvw");
@Override public LoginCredentials apply(@Nullable EncryptedPasswordAndPrivateKey dataAndKey) { if (dataAndKey == null) return null; try { KeySpec keySpec = Pems.privateKeySpec(dataAndKey.getPrivateKey()); KeyFactory kf = crypto.rsaKeyFactory(); PrivateKey privKey = kf.generatePrivate(keySpec); Cipher cipher = crypto.cipher("RSA"); cipher.init(Cipher.DECRYPT_MODE, privKey); byte[] cipherText = base64().decode(whitespace.matcher(dataAndKey.getEncryptedPassword()).replaceAll("")); byte[] plainText = cipher.doFinal(cipherText); String password = new String(plainText, UTF_8); return LoginCredentials.builder() .user("Administrator") .password(password) .noPrivateKey() .build(); } catch (Exception e) { throw Throwables.propagate(e); } } }
@Test public void testApply() throws Exception { WindowsLoginCredentialsFromEncryptedData f = new WindowsLoginCredentialsFromEncryptedData(new JCECrypto()); LoginCredentials credentials = f.apply(new EncryptedPasswordAndPrivateKey(ENCRYPTED_PASSWORD, PRIVATE_KEY)); assertEquals(credentials.getUser(), "Administrator"); assertEquals(credentials.getOptionalPassword().get(), "u4.y9mb;nR."); assertFalse(credentials.getOptionalPrivateKey().isPresent()); } }
EncryptedPasswordAndPrivateKey.builder().encryptedPassword(actual).privateKey(privateKey).build()).getOptionalPassword().get(), "bX7vvptvw");
@Override public LoginCredentials apply(@Nullable EncryptedPasswordAndPrivateKey dataAndKey) { if (dataAndKey == null) return null; try { KeySpec keySpec = Pems.privateKeySpec(dataAndKey.getPrivateKey()); KeyFactory kf = crypto.rsaKeyFactory(); PrivateKey privKey = kf.generatePrivate(keySpec); Cipher cipher = crypto.cipher("RSA"); cipher.init(Cipher.DECRYPT_MODE, privKey); byte[] cipherText = base64().decode(whitespace.matcher(dataAndKey.getEncryptedPassword()).replaceAll("")); byte[] plainText = cipher.doFinal(cipherText); String password = new String(plainText, UTF_8); return LoginCredentials.builder() .user("Administrator") .password(password) .noPrivateKey() .build(); } catch (Exception e) { throw Throwables.propagate(e); } } }