use of javax.crypto.spec.SecretKeySpec in project fxosstub by Jaxo.
the class Jwt method hashKey.
/*----------------------------------------------------------------base64Url-+
*/
/**
*/
/*
+-------------------------------------------------------------------------*/
private static String hashKey(String in) throws Exception {
Mac mac = Mac.getInstance(ALGO);
mac.init(new SecretKeySpec(paySecret.getBytes(ENC), ALGO));
return base64Url(mac.doFinal(in.getBytes(ENC)));
}
use of javax.crypto.spec.SecretKeySpec in project graylog2-server by Graylog2.
the class AESTools method decrypt.
@Nullable
public static String decrypt(String cipherText, String encryptionKey, String salt) {
try {
@SuppressFBWarnings("CIPHER_INTEGRITY") Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", "SunJCE");
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(salt.getBytes("UTF-8")));
return new String(cipher.doFinal(Hex.decode(cipherText)), "UTF-8");
} catch (Exception e) {
LOG.error("Could not decrypt value.", e);
}
return null;
}
use of javax.crypto.spec.SecretKeySpec in project bigbluebutton by bigbluebutton.
the class TurnServer method calculateRFC2104HMAC.
/**
* Computes RFC 2104-compliant HMAC signature.
* * @param data
* The data to be signed.
* @param key
* The signing key.
* @return
* The Base64-encoded RFC 2104-compliant HMAC signature.
* @throws
* java.security.SignatureException when signature generation fails
*/
private String calculateRFC2104HMAC(String data, String key) throws java.security.SignatureException {
String result;
try {
// get an hmac_sha1 key from the raw key bytes
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
// get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
// compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(data.getBytes());
// base64-encode the hmac
result = new String(Base64.encodeBase64(rawHmac));
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
return result;
}
use of javax.crypto.spec.SecretKeySpec in project UltimateAndroid by cymcsg.
the class TripleDES method decrypt.
public static String decrypt(byte[] message) throws Exception {
byte[] values = Base64decodingByte(message, 0);
final MessageDigest md = MessageDigest.getInstance("SHA-1");
final byte[] digestOfPassword = md.digest(token.getBytes("utf-8"));
final byte[] keyBytes = copyOf(digestOfPassword, 24);
for (int j = 0, k = 16; j < 8; ) {
keyBytes[k++] = keyBytes[j++];
}
final SecretKey key = new SecretKeySpec(keyBytes, "DESede");
String s1 = "12345678";
byte[] bytes = s1.getBytes();
final IvParameterSpec iv = new IvParameterSpec(bytes);
final Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
decipher.init(Cipher.DECRYPT_MODE, key, iv);
final byte[] plainText = decipher.doFinal(values);
return new String(plainText, "UTF-8");
}
use of javax.crypto.spec.SecretKeySpec in project zaproxy by zaproxy.
the class ZapNTLMEngineImpl method RC4.
/** Calculates RC4 */
static byte[] RC4(final byte[] value, final byte[] key) throws AuthenticationException {
try {
final Cipher rc4 = Cipher.getInstance("RC4");
rc4.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "RC4"));
return rc4.doFinal(value);
} catch (Exception e) {
throw new AuthenticationException(e.getMessage(), e);
}
}
Aggregations