use of java.security.InvalidKeyException 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 java.security.InvalidKeyException 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 java.security.InvalidKeyException in project OpenAttestation by OpenAttestation.
the class Diagnostic method trySignature.
private static void trySignature() {
String algorithmName = "SHA1withRSA";
try {
// generate keypair
// NoSuchAlgorithmException, NoSuchProviderException
KeyPair keyPair = KeyPairGenerator.getInstance("RSA", "BC").generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
String plaintext = "This is the message being signed";
// generate signature
// NoSuchAlgorithmException, NoSuchProviderException
Signature instance = Signature.getInstance("SHA1withRSAEncryption", "BC");
// InvalidKeyException
instance.initSign(privateKey);
// SignatureException
instance.update((plaintext).getBytes());
byte[] signature = instance.sign();
System.out.println("Generated SHA1 with RSA signature of length: " + signature.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: " + e.toString());
} catch (SignatureException e) {
System.err.println("Cannot generate signature: " + e.toString());
}
}
use of java.security.InvalidKeyException in project kafka by apache.
the class ScramFormatter method generateCredential.
public ScramCredential generateCredential(String password, int iterations) {
try {
byte[] salt = secureRandomBytes();
byte[] saltedPassword = saltedPassword(password, salt, iterations);
byte[] clientKey = clientKey(saltedPassword);
byte[] storedKey = storedKey(clientKey);
byte[] serverKey = serverKey(saltedPassword);
return new ScramCredential(salt, storedKey, serverKey, iterations);
} catch (InvalidKeyException e) {
throw new KafkaException("Could not create credential", e);
}
}
use of java.security.InvalidKeyException in project kafka by apache.
the class ScramSaslClient method handleServerFirstMessage.
private ClientFinalMessage handleServerFirstMessage(char[] password) throws SaslException {
try {
byte[] passwordBytes = formatter.normalize(new String(password));
this.saltedPassword = formatter.hi(passwordBytes, serverFirstMessage.salt(), serverFirstMessage.iterations());
ClientFinalMessage clientFinalMessage = new ClientFinalMessage("n,,".getBytes(StandardCharsets.UTF_8), serverFirstMessage.nonce());
byte[] clientProof = formatter.clientProof(saltedPassword, clientFirstMessage, serverFirstMessage, clientFinalMessage);
clientFinalMessage.proof(clientProof);
return clientFinalMessage;
} catch (InvalidKeyException e) {
throw new SaslException("Client final message could not be created", e);
}
}
Aggregations