@Override public char[] transform(final char[] passwordData) { byte[] passwordBytes = Strings.decodeBase64(new String(passwordData)); char[] password = new char[passwordBytes.length]; for (int i = 0; i < passwordBytes.length; i++) { password[i] = (char) passwordBytes[i]; } return password; } };
@Override public char[] transform(final char[] passwordData) { byte[] passwordBytes = Strings.decodeBase64(new String(passwordData)); char[] password = new char[passwordBytes.length * 2]; for (int i = 0; i < passwordBytes.length; i++) { password[2 * i] = HEX_CHARACTERS[(((int) passwordBytes[i]) & 0xf0) >> 4]; password[(2 * i) + 1] = HEX_CHARACTERS[(((int) passwordBytes[i]) & 0x0f)]; } return password; } };
@Override byte[] convert(final Object value, final ConfiguredObject object) { if(value instanceof byte[]) { return (byte[]) value; } else if(value == null) { return null; } else if(value instanceof String) { String interpolated = AbstractConfiguredObject.interpolate(object, (String) value); return Strings.decodeBase64(interpolated); } else { throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a byte[]"); } } };
private void decodeCertificate() { byte[] certificateEncoded = Strings.decodeBase64((String) getActualAttributes().get(CERTIFICATE)); try(ByteArrayInputStream input = new ByteArrayInputStream(certificateEncoded)) { CertificateFactory cf = CertificateFactory.getInstance("X.509"); _x509Certificate = (X509Certificate) cf.generateCertificate(input); } catch (CertificateException | IOException e) { throw new IllegalConfigurationException("Could not decode certificate", e); } }
HashedUser(String[] data, AuthenticationProvider<?> authenticationProvider) { if (data.length != 2) { throw new IllegalArgumentException("User Data should be length 2, username, password"); } _name = data[0]; byte[] encoded_password; try { encoded_password = data[1].getBytes(Base64MD5PasswordFilePrincipalDatabase.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { throw new ServerScopedRuntimeException("MD5 encoding not supported, even though the Java standard requires it",e); } _encodedPassword = encoded_password; byte[] decoded = Strings.decodeBase64(data[1]); _password = new char[decoded.length]; int index = 0; for (byte c : decoded) { _password[index++] = (char) c; } _authenticationProvider = authenticationProvider; }
if(_base64) _content = Strings.decodeBase64(parts[1]);
@Override public String decrypt(final String encrypted) { if(!isValidBase64(encrypted)) { throw new IllegalArgumentException("Encrypted value is not valid Base 64 data: '" + encrypted + "'"); } byte[] encryptedBytes = Strings.decodeBase64(encrypted); try { Cipher cipher = Cipher.getInstance(CIPHER_NAME); IvParameterSpec ivParameterSpec = new IvParameterSpec(encryptedBytes, 0, AES_INITIALIZATION_VECTOR_LENGTH); cipher.init(Cipher.DECRYPT_MODE, _secretKey, ivParameterSpec); return new String(readFromCipherStream(encryptedBytes, AES_INITIALIZATION_VECTOR_LENGTH, encryptedBytes.length - AES_INITIALIZATION_VECTOR_LENGTH, cipher), StandardCharsets.UTF_8); } catch (IOException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) { throw new IllegalArgumentException("Unable to decrypt secret", e); } }
public static PrivateKey readPrivateKey(InputStream input) throws IOException, GeneralSecurityException { byte[] content = toByteArray(input); String contentAsString = new String(content, StandardCharsets.US_ASCII); if(contentAsString.contains("-----BEGIN ") && contentAsString.contains(" PRIVATE KEY-----")) { BufferedReader lineReader = new BufferedReader(new StringReader(contentAsString)); String line; do { line = lineReader.readLine(); } while(line != null && !(line.startsWith("-----BEGIN ") && line.endsWith(" PRIVATE KEY-----"))); if(line != null) { StringBuilder keyBuilder = new StringBuilder(); while((line = lineReader.readLine()) != null) { if(line.startsWith("-----END ") && line.endsWith(" PRIVATE KEY-----")) { break; } keyBuilder.append(line); } content = Strings.decodeBase64(keyBuilder.toString()); } } return readPrivateKey(content, "RSA"); }
private void loadPrivateKeyAndCertificate() { byte[] privateKeyEncoded = Strings.decodeBase64((String) getActualAttributes().get(ENCODED_PRIVATE_KEY)); byte[] certificateEncoded = Strings.decodeBase64((String) getActualAttributes().get( ENCODED_CERTIFICATE)); try(ByteArrayInputStream input = new ByteArrayInputStream(certificateEncoded)) { CertificateFactory cf = CertificateFactory.getInstance("X.509"); _certificate = (X509Certificate) cf.generateCertificate(input); } catch (CertificateException | IOException e) { throw new IllegalConfigurationException("Could not decode certificate", e); } try { _privateKey = SSLUtil.readPrivateKey(privateKeyEncoded, _keyAlgorithm); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { throw new IllegalConfigurationException("Could not decode private key", e); } }
if(!Arrays.equals(_gs2Header, Strings.decodeBase64(parts[0].substring(2)))) byte[] proofBytes = Strings.decodeBase64(parts[parts.length-1].substring(2));
String[] credentials = (new String(Strings.decodeBase64(base64UsernameAndPassword), StandardCharsets.UTF_8)).split(":", 2); if (credentials.length == 2)
salt = Strings.decodeBase64(passwordFields[PasswordField.SALT.ordinal()]); storedKey = Strings.decodeBase64(passwordFields[PasswordField.STORED_KEY.ordinal()]); serverKey = Strings.decodeBase64(passwordFields[PasswordField.SERVER_KEY.ordinal()]); iterationCount = Integer.parseInt(passwordFields[PasswordField.ITERATION_COUNT.ordinal()]); exception = null;
if (passwordFields.length == 2) byte[] saltedPassword = Strings.decodeBase64(passwordFields[PasswordField.SALTED_PASSWORD.ordinal()]);
if("base64".equalsIgnoreCase(contentTransferEncoding)) body = Strings.decodeBase64((String) messageContent);
: Strings.decodeBase64(saslResponse); SubjectAuthenticationResult authenticationResult = subjectCreator.authenticate(saslNegotiator, saslResponseBytes); byte[] challenge = authenticationResult.getChallenge();