/** * Returns a new {@code ByteSource} instance representing the specified character array's bytes. The byte * array is obtained assuming {@code UTF-8} encoding. * * @param chars the character array to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified character array's bytes. */ public static ByteSource bytes(char[] chars) { return new SimpleByteSource(chars); }
/** * Returns a new {@code ByteSource} instance representing the specified ByteSource. * * @param source the ByteSource to represent as a new {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified ByteSource. */ public static ByteSource bytes(ByteSource source) { return new SimpleByteSource(source); }
/** * Returns a new {@code ByteSource} instance representing the specified byte array. * * @param bytes the bytes to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified byte array. */ public static ByteSource bytes(byte[] bytes) { return new SimpleByteSource(bytes); }
/** * Returns a new {@code ByteSource} instance representing the specified string's bytes. The byte * array is obtained assuming {@code UTF-8} encoding. * * @param string the string to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified string's bytes. */ public static ByteSource bytes(String string) { return new SimpleByteSource(string); }
/** * Returns a new {@code ByteSource} instance representing the specified File's bytes. * * @param file the file to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified File's bytes. */ public static ByteSource bytes(File file) { return new SimpleByteSource(file); }
/** * Returns a new {@code ByteSource} instance representing the specified InputStream's bytes. * * @param stream the InputStream to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified InputStream's bytes. */ public static ByteSource bytes(InputStream stream) { return new SimpleByteSource(stream); }
/** * Returns a new {@code ByteSource} instance representing the specified string's bytes. The byte * array is obtained assuming {@code UTF-8} encoding. * * @param string the string to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified string's bytes. */ public static ByteSource bytes(String string) { return new SimpleByteSource(string); }
/** * Returns a new {@code ByteSource} instance representing the specified File's bytes. * * @param file the file to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified File's bytes. */ public static ByteSource bytes(File file) { return new SimpleByteSource(file); }
public SimpleByteSource getDelegate() { if(delegate == null) { delegate = new SimpleByteSource(bytes); } return delegate; }
/** * Returns a new {@code ByteSource} instance representing the specified ByteSource. * * @param source the ByteSource to represent as a new {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified ByteSource. */ public static ByteSource bytes(ByteSource source) { return new SimpleByteSource(source); }
/** * Returns a new {@code ByteSource} instance representing the specified InputStream's bytes. * * @param stream the InputStream to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified InputStream's bytes. */ public static ByteSource bytes(InputStream stream) { return new SimpleByteSource(stream); }
/** * Returns a new {@code ByteSource} instance representing the specified byte array. * * @param bytes the bytes to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified byte array. */ public static ByteSource bytes(byte[] bytes) { return new SimpleByteSource(bytes); }
/** * Returns a new {@code ByteSource} instance representing the specified character array's bytes. The byte * array is obtained assuming {@code UTF-8} encoding. * * @param chars the character array to represent as a {@code ByteSource} instance. * @return a new {@code ByteSource} instance representing the specified character array's bytes. */ public static ByteSource bytes(char[] chars) { return new SimpleByteSource(chars); }
public class MyPrivateSaltingPasswortService extends DefaultPasswordService { public MyPrivateSaltingPasswortService() { super(); HashService service = getHashService(); if (service instanceof DefaultHashService) { ((DefaultHashService) service).setPrivateSalt( new SimpleByteSource("MySuperSecretPrivateSalt")); } } }
public ByteSource nextBytes(int numBytes) { if (numBytes <= 0) { throw new IllegalArgumentException("numBytes argument must be a positive integer (1 or larger)"); } byte[] bytes = new byte[numBytes]; this.secureRandom.nextBytes(bytes); return new SimpleByteSource(bytes); } }
private ByteSource decrypt(byte[] ciphertext, byte[] key, byte[] iv) throws CryptoException { if (log.isTraceEnabled()) { log.trace("Attempting to decrypt incoming byte array of length " + (ciphertext != null ? ciphertext.length : 0)); } byte[] decrypted = crypt(ciphertext, key, iv, javax.crypto.Cipher.DECRYPT_MODE); return decrypted == null ? null : new SimpleByteSource(decrypted); }
public AuthenticationInfoBuilder salt(byte[] salt) { this.salt(new SimpleByteSource(salt)); return this; }
private ByteSource encrypt(byte[] plaintext, byte[] key, byte[] iv, boolean prependIv) throws CryptoException { final int MODE = javax.crypto.Cipher.ENCRYPT_MODE; byte[] output; if (prependIv && iv != null && iv.length > 0) { byte[] encrypted = crypt(plaintext, key, iv, MODE); output = new byte[iv.length + encrypted.length]; //now copy the iv bytes + encrypted bytes into one output array: // iv bytes: System.arraycopy(iv, 0, output, 0, iv.length); // + encrypted bytes: System.arraycopy(encrypted, 0, output, iv.length, encrypted.length); } else { output = crypt(plaintext, key, iv, MODE); } if (log.isTraceEnabled()) { log.trace("Incoming plaintext of size " + (plaintext != null ? plaintext.length : 0) + ". Ciphertext " + "byte array is size " + (output != null ? output.length : 0)); } return new SimpleByteSource(output); }
@Configuration public class SecurityConfiguration { private static final String PRIVATE_SALT = "ourprivatesalt"; private PasswordService passwordService; private PasswordMatcher credentialsMatcher = new PasswordAndSystemCredentialsMatcher(); private AuthenticatingSecurityManager securityManager; @Bean public PasswordService passwordService() { if (passwordService == null) { DefaultPasswordService defaultPasswordService = new DefaultPasswordService(); passwordService = defaultPasswordService; DefaultHashService defaultHashService = (DefaultHashService) defaultPasswordService.getHashService(); defaultHashService.setPrivateSalt(new SimpleByteSource(PRIVATE_SALT)); } return passwordService; } @Bean public CredentialsMatcher credentialsMatcher() { credentialsMatcher.setPasswordService(passwordService()); return credentialsMatcher; }