private static byte[] bytesUtf8(String s) { if (s == null) { return null; } return Utf8.encode(s); // need to check if Utf8.encode() runs in constant time (probably not). This may leak length of string. }
public static boolean isBase64(byte[] bytes) { try { decode(bytes); } catch (InvalidBase64CharacterException e) { return false; } return true; }
public static byte[] encode(byte[] bytes) { return encodeBytesToBytes(bytes, 0, bytes.length, NO_OPTIONS); }
private byte[] decode(CharSequence encodedPassword) { return Hex.decode(encodedPassword); }
@Test(expected = IllegalArgumentException.class) public void isBase64RejectsInvalidLength() { Base64.isBase64(new byte[] { (byte) 'A' }); } }
public static byte[] decode(byte[] bytes) { return decode(bytes, 0, bytes.length, NO_OPTIONS); }
/** * Constructs a standard password encoder with a secret value as well as iterations * and hash. * * @param secret the secret * @param iterations the number of iterations. Users should aim for taking about .5 * seconds on their own system. * @param hashWidth the size of the hash */ public Pbkdf2PasswordEncoder(CharSequence secret, int iterations, int hashWidth) { this.secret = Utf8.encode(secret); this.iterations = iterations; this.hashWidth = hashWidth; }
private byte[] decode(CharSequence encodedPassword) { return Hex.decode(encodedPassword); }
public static byte[] encode(byte[] bytes) { return encodeBytesToBytes(bytes, 0, bytes.length, NO_OPTIONS); }
@Test(expected = NullPointerException.class) public void isBase64RejectsNull() { Base64.isBase64(null); }
public static boolean isBase64(byte[] bytes) { try { decode(bytes); } catch (InvalidBase64CharacterException e) { return false; } return true; }
private static byte[] bytesUtf8(String s) { if (s == null) { return null; } return Utf8.encode(s); // need to check if Utf8.encode() runs in constant time (probably not). This may leak length of string. }
public static byte[] decode(byte[] bytes) { return decode(bytes, 0, bytes.length, NO_OPTIONS); }
/** * Constructs a standard password encoder with a secret value as well as iterations * and hash. * * @param secret the secret * @param iterations the number of iterations. Users should aim for taking about .5 * seconds on their own system. * @param hashWidth the size of the hash */ public Pbkdf2PasswordEncoder(CharSequence secret, int iterations, int hashWidth) { this.secret = Utf8.encode(secret); this.iterations = iterations; this.hashWidth = hashWidth; }