use of javax.crypto.spec.SecretKeySpec in project Talon-for-Twitter by klinker24.
the class TwitterDMPicHelper method computeSignature.
private static String computeSignature(String baseString, String keyString) throws GeneralSecurityException, UnsupportedEncodingException {
SecretKey secretKey = null;
byte[] keyBytes = keyString.getBytes();
secretKey = new SecretKeySpec(keyBytes, "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKey);
byte[] text = baseString.getBytes();
return new String(BASE64Encoder.encode(mac.doFinal(text))).trim();
}
use of javax.crypto.spec.SecretKeySpec in project Talon-for-Twitter by klinker24.
the class TwitterMultipleImageHelper method computeSignature.
private static String computeSignature(String baseString, String keyString) throws GeneralSecurityException, UnsupportedEncodingException {
SecretKey secretKey = null;
byte[] keyBytes = keyString.getBytes();
secretKey = new SecretKeySpec(keyBytes, "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKey);
byte[] text = baseString.getBytes();
return new String(BASE64Encoder.encode(mac.doFinal(text))).trim();
}
use of javax.crypto.spec.SecretKeySpec in project hbase by apache.
the class TestEncryption method checkTransformSymmetry.
private void checkTransformSymmetry(byte[] keyBytes, byte[] iv, byte[] plaintext) throws Exception {
LOG.info("checkTransformSymmetry: AES, plaintext length = " + plaintext.length);
Configuration conf = HBaseConfiguration.create();
String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
Cipher aes = Encryption.getCipher(conf, algorithm);
Key key = new SecretKeySpec(keyBytes, algorithm);
Encryptor e = aes.getEncryptor();
e.setKey(key);
e.setIv(iv);
e.reset();
ByteArrayOutputStream encOut = new ByteArrayOutputStream();
Encryption.encrypt(encOut, plaintext, 0, plaintext.length, e);
byte[] encrypted = encOut.toByteArray();
Decryptor d = aes.getDecryptor();
d.setKey(key);
d.setIv(iv);
d.reset();
ByteArrayInputStream encIn = new ByteArrayInputStream(encrypted);
ByteArrayOutputStream decOut = new ByteArrayOutputStream();
Encryption.decrypt(decOut, encIn, plaintext.length, d);
byte[] result = decOut.toByteArray();
assertEquals("Decrypted result has different length than plaintext", result.length, plaintext.length);
assertTrue("Transformation was not symmetric", Bytes.equals(result, plaintext));
}
use of javax.crypto.spec.SecretKeySpec in project hadoop by apache.
the class AbstractJavaKeyStoreProvider method innerSetCredential.
CredentialEntry innerSetCredential(String alias, char[] material) throws IOException {
writeLock.lock();
try {
keyStore.setKeyEntry(alias, new SecretKeySpec(new String(material).getBytes("UTF-8"), "AES"), password, null);
} catch (KeyStoreException e) {
throw new IOException("Can't store credential " + alias + " in " + this, e);
} finally {
writeLock.unlock();
}
changed = true;
return new CredentialEntry(alias, material);
}
use of javax.crypto.spec.SecretKeySpec in project RxCache by VictorAlbertos.
the class BuiltInEncryptor method generateSecretKey.
private SecretKeySpec generateSecretKey(String key) throws Exception {
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(key.getBytes("UTF-8"));
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(KEY_LENGTH, secureRandom);
SecretKey secretKey = keyGenerator.generateKey();
return new SecretKeySpec(secretKey.getEncoded(), "AES");
}
Aggregations