/** * Decode given payload and decrypt it to original. * All necessary parameters are supplied through {@link Builder}. * @param encodedPayload text to decode and decrypt * @return decrypted secret * @throws GeneralSecurityException when problem occurs like non-existent algorithm or similar problems */ public char[] decodeAndDecrypt(String encodedPayload) throws GeneralSecurityException { return byteArrayDecode(decrypt(decodeUsingAlphabet(encodedPayload))); }
/** * Encrypt a payload and encode the result using {@link Alphabet} given to builder. * All necessary parameters are supplied through {@link Builder}. * @param payload secret to encrypt * @return String encrypted and encoded using given parameters * @throws GeneralSecurityException when problem occurs like non-existent algorithm or similar problems */ public String encryptAndEncode(char[] payload) throws GeneralSecurityException { return encodeUsingAlphabet(encrypt(charArrayEncode(payload))); }
private byte[] decodeUsingAlphabet(String payload) { if (picketBoxCompatibility) { return picketBoxBase64Decode(payload); } else { ByteIterator byteIterator = isBase64(alphabet) ? CodePointIterator.ofString(payload).base64Decode(getAlphabet64(alphabet), usePadding) : CodePointIterator.ofString(payload).base32Decode(getAlphabet32(alphabet)); return byteIterator.drain(); } }
private String encodeUsingAlphabet(byte[] payload) { if (picketBoxCompatibility) { return picketBoxBased64Encode(payload); } else { CodePointIterator codePointIterator = isBase64(alphabet) ? ByteIterator.ofBytes(payload).base64Encode(getAlphabet64(alphabet), usePadding) : ByteIterator.ofBytes(payload).base32Encode(getAlphabet32(alphabet)); return codePointIterator.drainToString(); } }
/** * Returns encrypted IV (initial vector) as generated by AES algorithm in the process of encryption. * Other algorithms are not using it. * In case of no such data available it returns {@code null}. * It uses already set {@link Alphabet} to encode it. * @return encoded form of IV or {@code null} when not available */ public String getEncodedIV() { if (algorithmParameters != null) { try { PBEParameterSpec spec = algorithmParameters.getParameterSpec(PBEParameterSpec.class); AlgorithmParameterSpec algSpec = spec.getParameterSpec(); if (algSpec instanceof IvParameterSpec) { return encodeUsingAlphabet(((IvParameterSpec) algSpec).getIV()); } } catch (InvalidParameterSpecException e) { return null; } } return null; }
return new PasswordBasedEncryptionUtil(createAndInitCipher(deriveSecretKey()), algorithmParameters, alphabet, usePadding, picketBoxCompatibility);
private String encodeUsingAlphabet(byte[] payload) { if (picketBoxCompatibility) { return picketBoxBased64Encode(payload); } else { CodePointIterator codePointIterator = isBase64(alphabet) ? ByteIterator.ofBytes(payload).base64Encode(getAlphabet64(alphabet), usePadding) : ByteIterator.ofBytes(payload).base32Encode(getAlphabet32(alphabet)); return codePointIterator.drainToString(); } }
/** * Returns encrypted IV (initial vector) as generated by AES algorithm in the process of encryption. * Other algorithms are not using it. * In case of no such data available it returns {@code null}. * It uses already set {@link Alphabet} to encode it. * @return encoded form of IV or {@code null} when not available */ public String getEncodedIV() { if (algorithmParameters != null) { try { PBEParameterSpec spec = algorithmParameters.getParameterSpec(PBEParameterSpec.class); AlgorithmParameterSpec algSpec = spec.getParameterSpec(); if (algSpec instanceof IvParameterSpec) { return encodeUsingAlphabet(((IvParameterSpec) algSpec).getIV()); } } catch (InvalidParameterSpecException e) { return null; } } return null; }
return new PasswordBasedEncryptionUtil(createAndInitCipher(deriveSecretKey()), algorithmParameters, alphabet, usePadding, picketBoxCompatibility);
private byte[] decodeUsingAlphabet(String payload) { if (picketBoxCompatibility) { return picketBoxBase64Decode(payload); } else { ByteIterator byteIterator = isBase64(alphabet) ? CodePointIterator.ofString(payload).base64Decode(getAlphabet64(alphabet), usePadding) : CodePointIterator.ofString(payload).base32Decode(getAlphabet32(alphabet)); return byteIterator.drain(); } }
private String encodeUsingAlphabet(byte[] payload) { if (picketBoxCompatibility) { return picketBoxBased64Encode(payload); } else { CodePointIterator codePointIterator = isBase64(alphabet) ? ByteIterator.ofBytes(payload).base64Encode(getAlphabet64(alphabet), usePadding) : ByteIterator.ofBytes(payload).base32Encode(getAlphabet32(alphabet)); return codePointIterator.drainToString(); } }
/** * Decode given payload and decrypt it to original. * All necessary parameters are supplied through {@link Builder}. * @param encodedPayload text to decode and decrypt * @return decrypted secret * @throws GeneralSecurityException when problem occurs like non-existent algorithm or similar problems */ public char[] decodeAndDecrypt(String encodedPayload) throws GeneralSecurityException { return byteArrayDecode(decrypt(decodeUsingAlphabet(encodedPayload))); }
/** * Encrypt a payload and encode the result using {@link Alphabet} given to builder. * All necessary parameters are supplied through {@link Builder}. * @param payload secret to encrypt * @return String encrypted and encoded using given parameters * @throws GeneralSecurityException when problem occurs like non-existent algorithm or similar problems */ public String encryptAndEncode(char[] payload) throws GeneralSecurityException { return encodeUsingAlphabet(encrypt(charArrayEncode(payload))); }
/** * Returns encrypted IV (initial vector) as generated by AES algorithm in the process of encryption. * Other algorithms are not using it. * In case of no such data available it returns {@code null}. * It uses already set {@link Alphabet} to encode it. * @return encoded form of IV or {@code null} when not available */ public String getEncodedIV() { if (algorithmParameters != null) { try { PBEParameterSpec spec = algorithmParameters.getParameterSpec(PBEParameterSpec.class); AlgorithmParameterSpec algSpec = spec.getParameterSpec(); if (algSpec instanceof IvParameterSpec) { return encodeUsingAlphabet(((IvParameterSpec) algSpec).getIV()); } } catch (InvalidParameterSpecException e) { return null; } } return null; }
return new PasswordBasedEncryptionUtil(createAndInitCipher(deriveSecretKey()), algorithmParameters, alphabet, usePadding, picketBoxCompatibility);
private byte[] decodeUsingAlphabet(String payload) { if (picketBoxCompatibility) { return picketBoxBase64Decode(payload); } else { ByteIterator byteIterator = isBase64(alphabet) ? CodePointIterator.ofString(payload).base64Decode(getAlphabet64(alphabet), usePadding) : CodePointIterator.ofString(payload).base32Decode(getAlphabet32(alphabet)); return byteIterator.drain(); } }
private String encodeUsingAlphabet(byte[] payload) { if (picketBoxCompatibility) { return picketBoxBased64Encode(payload); } else { CodePointIterator codePointIterator = isBase64(alphabet) ? ByteIterator.ofBytes(payload).base64Encode(getAlphabet64(alphabet), usePadding) : ByteIterator.ofBytes(payload).base32Encode(getAlphabet32(alphabet)); return codePointIterator.drainToString(); } }
/** * Decode given payload and decrypt it to original. * All necessary parameters are supplied through {@link Builder}. * @param encodedPayload text to decode and decrypt * @return decrypted secret * @throws GeneralSecurityException when problem occurs like non-existent algorithm or similar problems */ public char[] decodeAndDecrypt(String encodedPayload) throws GeneralSecurityException { return byteArrayDecode(decrypt(decodeUsingAlphabet(encodedPayload))); }
/** * Encrypt a payload and encode the result using {@link Alphabet} given to builder. * All necessary parameters are supplied through {@link Builder}. * @param payload secret to encrypt * @return String encrypted and encoded using given parameters * @throws GeneralSecurityException when problem occurs like non-existent algorithm or similar problems */ public String encryptAndEncode(char[] payload) throws GeneralSecurityException { return encodeUsingAlphabet(encrypt(charArrayEncode(payload))); }
/** * Returns encrypted IV (initial vector) as generated by AES algorithm in the process of encryption. * Other algorithms are not using it. * In case of no such data available it returns {@code null}. * It uses already set {@link Alphabet} to encode it. * @return encoded form of IV or {@code null} when not available */ public String getEncodedIV() { if (algorithmParameters != null) { try { PBEParameterSpec spec = algorithmParameters.getParameterSpec(PBEParameterSpec.class); AlgorithmParameterSpec algSpec = spec.getParameterSpec(); if (algSpec instanceof IvParameterSpec) { return encodeUsingAlphabet(((IvParameterSpec) algSpec).getIV()); } } catch (InvalidParameterSpecException e) { return null; } } return null; }