use of java.security.GeneralSecurityException in project poi by apache.
the class BinaryRC4Decryptor method verifyPassword.
@Override
public boolean verifyPassword(String password) {
EncryptionVerifier ver = getEncryptionInfo().getVerifier();
SecretKey skey = generateSecretKey(password, ver);
try {
Cipher cipher = initCipherForBlock(null, 0, getEncryptionInfo(), skey, Cipher.DECRYPT_MODE);
byte[] encryptedVerifier = ver.getEncryptedVerifier();
byte[] verifier = new byte[encryptedVerifier.length];
cipher.update(encryptedVerifier, 0, encryptedVerifier.length, verifier);
setVerifier(verifier);
byte[] encryptedVerifierHash = ver.getEncryptedVerifierHash();
byte[] verifierHash = cipher.doFinal(encryptedVerifierHash);
HashAlgorithm hashAlgo = ver.getHashAlgorithm();
MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo);
byte[] calcVerifierHash = hashAlg.digest(verifier);
if (Arrays.equals(calcVerifierHash, verifierHash)) {
setSecretKey(skey);
return true;
}
} catch (GeneralSecurityException e) {
throw new EncryptedDocumentException(e);
}
return false;
}
use of java.security.GeneralSecurityException in project karaf by apache.
the class OsgiKeystoreManager method createSSLContext.
public SSLContext createSSLContext(String provider, String protocol, String algorithm, String keyStore, String keyAlias, String trustStore, long timeout) throws GeneralSecurityException {
if (!this.checkForKeystoresAvailability(keyStore, keyAlias, trustStore, timeout)) {
throw new GeneralSecurityException("Unable to lookup configured keystore and/or truststore");
}
KeystoreInstance keyInstance = getKeystore(keyStore);
if (keyInstance != null && keyInstance.isKeystoreLocked()) {
throw new KeystoreIsLocked("Keystore '" + keyStore + "' is locked");
}
if (keyInstance != null && keyInstance.isKeyLocked(keyAlias)) {
throw new KeystoreIsLocked("Key '" + keyAlias + "' in keystore '" + keyStore + "' is locked");
}
KeystoreInstance trustInstance = trustStore == null ? null : getKeystore(trustStore);
if (trustInstance != null && trustInstance.isKeystoreLocked()) {
throw new KeystoreIsLocked("Keystore '" + trustStore + "' is locked");
}
SSLContext context;
if (provider == null) {
context = SSLContext.getInstance(protocol);
} else {
context = SSLContext.getInstance(protocol, provider);
}
context.init(keyInstance == null ? null : keyInstance.getKeyManager(algorithm, keyAlias), trustInstance == null ? null : trustInstance.getTrustManager(algorithm), new SecureRandom());
return context;
}
use of java.security.GeneralSecurityException in project spring-boot by spring-projects.
the class TokenValidator method hasValidSignature.
private boolean hasValidSignature(Token token, String key) {
try {
PublicKey publicKey = getPublicKey(key);
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initVerify(publicKey);
signature.update(token.getContent());
return signature.verify(token.getSignature());
} catch (GeneralSecurityException ex) {
return false;
}
}
use of java.security.GeneralSecurityException in project robovm by robovm.
the class GeneralSecurityExceptionTest method testGeneralSecurityException02.
/**
* Test for <code>GeneralSecurityException(String)</code> constructor
* Assertion: constructs GeneralSecurityException with detail message msg.
* Parameter <code>msg</code> is not null.
*/
public void testGeneralSecurityException02() {
GeneralSecurityException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new GeneralSecurityException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
}
use of java.security.GeneralSecurityException in project robovm by robovm.
the class GeneralSecurityExceptionTest method testGeneralSecurityException04.
/**
* Test for <code>GeneralSecurityException(Throwable)</code> constructor
* Assertion: constructs GeneralSecurityException when <code>cause</code>
* is null
*/
public void testGeneralSecurityException04() {
Throwable cause = null;
GeneralSecurityException tE = new GeneralSecurityException(cause);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
Aggregations