use of javax.crypto.Mac in project Openfire by igniterealtime.
the class N method A.
public static byte[] A(byte[] abyte0, byte[] abyte1, int i, byte[] abyte2) {
try {
SecretKeySpec secretkeyspec = new SecretKeySpec(abyte2, "hmacSHA256");
Mac mac = Mac.getInstance("hmacSHA256");
mac.init(secretkeyspec);
mac.update(abyte1, 0, i);
byte[] abyte3 = mac.doFinal();
secretkeyspec = new SecretKeySpec(abyte0, "hmacSHA256");
mac = Mac.getInstance("hmacSHA256");
mac.init(secretkeyspec);
return mac.doFinal(abyte3);
} catch (NoSuchAlgorithmException nosuchalgorithmexception) {
E.error(nosuchalgorithmexception.getMessage(), nosuchalgorithmexception);
} catch (InvalidKeyException invalidkeyexception) {
E.error(invalidkeyexception.getMessage(), invalidkeyexception);
}
return null;
}
use of javax.crypto.Mac in project OpenAttestation by OpenAttestation.
the class Diagnostic method tryMacWithPassword.
private static void tryMacWithPassword(String algorithmName, String message, String password) {
try {
SecretKeySpec key = new SecretKeySpec(password.getBytes(), algorithmName);
// a string like "HmacSHA256"
Mac mac = Mac.getInstance(algorithmName, "BC");
mac.init(key);
byte[] digest = mac.doFinal(message.getBytes());
System.out.println("Created " + algorithmName + " digest of length " + digest.length);
} catch (NoSuchProviderException e) {
System.err.println("Cannot use provider: BC: " + e.toString());
} catch (NoSuchAlgorithmException e) {
System.err.println("Cannot use algorithm: " + algorithmName + ": " + e.toString());
} catch (InvalidKeyException e) {
System.err.println("Cannot use key: " + password + ": " + e.toString());
}
}
use of javax.crypto.Mac in project Signal-Android by WhisperSystems.
the class DecryptingPartInputStream method initializeMac.
private Mac initializeMac(SecretKeySpec key) throws NoSuchAlgorithmException, InvalidKeyException {
Mac hmac = Mac.getInstance("HmacSHA1");
hmac.init(key);
return hmac;
}
use of javax.crypto.Mac in project Openfire by igniterealtime.
the class Crypto method getHmacSha1.
public static Byte[] getHmacSha1(Byte[] key, Byte[] buffer) {
try {
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(new SecretKeySpec(BitAssistant.bytesFromArray(key), "HmacSHA1"));
return BitAssistant.bytesToArray(mac.doFinal(BitAssistant.bytesFromArray(buffer)));
} catch (Exception e) {
return new Byte[0];
}
}
use of javax.crypto.Mac in project android_frameworks_base by ResurrectionRemix.
the class MacAuthenticatedInputStreamTest method testString1Authenticate_NullTag_Failure.
public void testString1Authenticate_NullTag_Failure() throws Exception {
Mac mac = Mac.getInstance("HMAC-SHA1");
mac.init(HMAC_KEY_1);
MacAuthenticatedInputStream is = new MacAuthenticatedInputStream(mTestStream1, mac);
assertTrue(Arrays.equals(TEST_STRING_1, Streams.readFully(is)));
assertFalse(is.isTagEqual(null));
}
Aggregations