/** * Gets a hex encoded random string. * * @param numBytes number of bytes of randomness. */ public static String getRandomString(int numBytes) { return new String(Hex.encodeHex(getRandomBytes(numBytes))); }
/** * Gets a hex encoded random string. * * @param numBytes number of bytes of randomness. */ public static String getRandomString(int numBytes) { return new String(Hex.encodeHex(getRandomBytes(numBytes))); }
/** * Gets a hex encoded random string. * * @param numBytes number of bytes of randomness. */ public static String getRandomString(int numBytes) { return new String(Hex.encodeHex(getRandomBytes(numBytes))); }
/** * Gets a hex encoded random string. * * @param numBytes number of bytes of randomness. */ public static String getRandomString(int numBytes) { return new String(Hex.encodeHex(getRandomBytes(numBytes))); }
/** * @return a random string of digits of the specified length. */ public static String getRandomDigits(int len) { byte[] random = getRandomBytes(len); StringBuilder out = new StringBuilder(len); for (int i = 0; i < len; ++i) { out.append(DIGITS[Math.abs(random[i] % DIGITS.length)]); } return out.toString(); }
/** * @return a random string of digits of the specified length. */ public static String getRandomDigits(int len) { byte[] random = getRandomBytes(len); StringBuilder out = new StringBuilder(len); for (int i = 0; i < len; ++i) { out.append(DIGITS[Math.abs(random[i] % DIGITS.length)]); } return out.toString(); }
/** * @return a random string of digits of the specified length. */ public static String getRandomDigits(int len) { byte[] random = getRandomBytes(len); StringBuilder out = new StringBuilder(len); for (int i = 0; i < len; ++i) { out.append(DIGITS[Math.abs(random[i] % DIGITS.length)]); } return out.toString(); }
/** * @return a random string of digits of the specified length. */ public static String getRandomDigits(int len) { byte[] random = getRandomBytes(len); StringBuilder out = new StringBuilder(len); for (int i = 0; i < len; ++i) { out.append(DIGITS[Math.abs(random[i] % DIGITS.length)]); } return out.toString(); }
/** * @return a random string of digits of the specified length. */ public static String getRandomDigits(int len) { byte[] random = getRandomBytes(len); StringBuilder out = new StringBuilder(len); for (int i = 0; i < len; ++i) { out.append(DIGITS[Math.abs(random[i] % DIGITS.length)]); } return out.toString(); }
@Inject public OAuthCrypterProvider(@Named("shindig.signing.state-key") String stateCrypterPath) throws IOException { if (StringUtils.isBlank(stateCrypterPath)) { LOG.info("Using random key for OAuth client-side state encryption"); crypter = new BasicBlobCrypter(Crypto.getRandomBytes(BasicBlobCrypter.MASTER_KEY_MIN_LEN)); } else { LOG.info("Using file " + stateCrypterPath + " for OAuth client-side state encryption"); crypter = new BasicBlobCrypter(new File(stateCrypterPath)); } }
@Inject public OAuthCrypterProvider(@Named("shindig.signing.state-key") String stateCrypterPath) throws IOException { if (StringUtils.isBlank(stateCrypterPath)) { LOG.info("Using random key for OAuth client-side state encryption"); crypter = new BasicBlobCrypter(Crypto.getRandomBytes(BasicBlobCrypter.MASTER_KEY_MIN_LEN)); } else { LOG.info("Using file " + stateCrypterPath + " for OAuth client-side state encryption"); crypter = new BasicBlobCrypter(new File(stateCrypterPath)); } }
@Before public void setUp() { crypter = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA1); crypter256 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA256); crypter384 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA384); crypter512 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA512); crypters.add(crypter); crypters.add(crypter256); crypters.add(crypter384); crypters.add(crypter512); crypter.timeSource = timeSource; }
@Before public void setUp() { crypter = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA1); crypter256 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA256); crypter384 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA384); crypter512 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA512); crypters.add(crypter); crypters.add(crypter256); crypters.add(crypter384); crypters.add(crypter512); crypter.timeSource = timeSource; }
@Before public void setUp() { crypter = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA1); crypter256 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA256); crypter384 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA384); crypter512 = new BasicBlobCrypter(Crypto.getRandomBytes(20),HMACType.HMACSHA512); crypters.add(crypter); crypters.add(crypter256); crypters.add(crypter384); crypters.add(crypter512); crypter.timeSource = timeSource; }
@Before public void setUp() { crypter = new BasicBlobCrypter(Crypto.getRandomBytes(20)); crypter.timeSource = timeSource; }
@Test public void testBase32() throws Exception { StringEncoding encoder = new StringEncoding( "0123456789abcdefghijklmnopqrstuv".toCharArray()); testEncoding(encoder, new byte[] { 0 }, "00"); testEncoding(encoder, new byte[] { 0, 0 }, "0000"); testEncoding(encoder, new byte[] { 10, 0 }, "1800"); testRoundTrip(encoder, Crypto.getRandomBytes(1)); testRoundTrip(encoder, Crypto.getRandomBytes(2)); testRoundTrip(encoder, Crypto.getRandomBytes(3)); testRoundTrip(encoder, Crypto.getRandomBytes(20)); testRoundTrip(encoder, Crypto.getRandomBytes(30)); }
@Before public void setUp() { crypter = new BasicBlobCrypter(Crypto.getRandomBytes(20)); crypter.timeSource = timeSource; }
@Test public void testAes128Cbc() throws Exception { byte[] key = Crypto.getRandomBytes(Crypto.CIPHER_KEY_LEN); for (byte i=0; i < 50; i++) { byte[] orig = new byte[i]; for (byte j=0; j < i; j++) { orig[j] = j; } byte[] cipherText = Crypto.aes128cbcEncrypt(key, orig); byte[] plainText = Crypto.aes128cbcDecrypt(key, cipherText); assertArrayEquals("Array of length " + i, orig, plainText); } }
@Test public void testAes128Cbc() throws Exception { byte[] key = Crypto.getRandomBytes(Crypto.CIPHER_KEY_LEN); for (byte i=0; i < 50; i++) { byte[] orig = new byte[i]; for (byte j=0; j < i; j++) { orig[j] = j; } byte[] cipherText = Crypto.aes128cbcEncrypt(key, orig); byte[] plainText = Crypto.aes128cbcDecrypt(key, cipherText); assertArrayEquals("Array of length " + i, orig, plainText); } }
@Test public void testAes128Cbc() throws Exception { byte[] key = Crypto.getRandomBytes(Crypto.CIPHER_KEY_LEN); for (byte i=0; i < 50; i++) { byte[] orig = new byte[i]; for (byte j=0; j < i; j++) { orig[j] = j; } byte[] cipherText = Crypto.aes128cbcEncrypt(key, orig); byte[] plainText = Crypto.aes128cbcDecrypt(key, cipherText); assertArrayEquals("Array of length " + i, orig, plainText); } }