use of javax.crypto.SecretKey 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.SecretKey in project Android-Terminal-Emulator by jackpal.
the class ShortcutEncryption method generateKeys.
/**
* Generates new secret keys suitable for the encryption scheme described
* above.
*
* @throws GeneralSecurityException if an error occurs during key generation.
*/
public static Keys generateKeys() throws GeneralSecurityException {
KeyGenerator gen = KeyGenerator.getInstance(ENC_ALGORITHM);
gen.init(KEYLEN);
SecretKey encKey = gen.generateKey();
/* XXX: It's probably unnecessary to create a different keygen for the
* MAC, but JCA's API design suggests we should just in case ... */
gen = KeyGenerator.getInstance(MAC_ALGORITHM);
gen.init(KEYLEN);
SecretKey macKey = gen.generateKey();
return new Keys(encKey, macKey);
}
use of javax.crypto.SecretKey in project hadoop by apache.
the class RMStateStore method getCredentialsFromAppAttempt.
public Credentials getCredentialsFromAppAttempt(RMAppAttempt appAttempt) {
Credentials credentials = new Credentials();
SecretKey clientTokenMasterKey = appAttempt.getClientTokenMasterKey();
if (clientTokenMasterKey != null) {
credentials.addSecretKey(AM_CLIENT_TOKEN_MASTER_KEY_NAME, clientTokenMasterKey.getEncoded());
}
return credentials;
}
use of javax.crypto.SecretKey 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");
}
use of javax.crypto.SecretKey in project DataX by alibaba.
the class SecretUtil method encrypt3DES.
/**
* 加密 DESede<br>
* 用密钥加密
*
* @param data 裸的原始数据
* @param key 加密的密钥
* @return 结果也采用base64加密
* @throws Exception
*/
public static String encrypt3DES(String data, String key) {
try {
// 生成密钥
SecretKey desKey = new SecretKeySpec(build3DesKey(key), KEY_ALGORITHM_3DES);
// 对数据加密
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM_3DES);
cipher.init(Cipher.ENCRYPT_MODE, desKey);
return encryptBASE64(cipher.doFinal(data.getBytes(ENCODING)));
} catch (Exception e) {
throw DataXException.asDataXException(FrameworkErrorCode.SECRET_ERROR, "3重DES加密出错", e);
}
}
Aggregations