use of java.security.InvalidParameterException in project robovm by robovm.
the class SignerTest method test_setKeyPairLjava_security_KeyPair.
/**
* java.security.Signer#setKeyPair(java.security.KeyPair)
*/
public void test_setKeyPairLjava_security_KeyPair() throws Exception {
// test: NullPointerException if pair is null
try {
new SignerStub("name").setKeyPair(null);
fail("No expected NullPointerException");
} catch (NullPointerException e) {
}
try {
KeyPair kp = new KeyPair(null, null);
SignerStub s = new SignerStub("name");
s.setKeyPair(kp);
} catch (InvalidParameterException e) {
// ok
}
}
use of java.security.InvalidParameterException in project zaproxy by zaproxy.
the class ExtensionBreak method addHttpBreakpoint.
public void addHttpBreakpoint(String string, String location, String match, boolean inverse, boolean ignoreCase) {
Location loc;
Match mtch;
try {
loc = Location.valueOf(location);
} catch (Exception e) {
throw new InvalidParameterException("location must be one of " + Arrays.toString(Location.values()));
}
try {
mtch = Match.valueOf(match);
} catch (Exception e) {
throw new InvalidParameterException("match must be one of " + Arrays.toString(Match.values()));
}
this.addBreakpoint(new HttpBreakpointMessage(string, loc, mtch, inverse, ignoreCase));
}
use of java.security.InvalidParameterException in project jforum2 by rafaelsteil.
the class SystemGlobals method buildSystem.
private void buildSystem(String appPath, String mainConfigurationFile) {
if (mainConfigurationFile == null) {
throw new InvalidParameterException("defaultConfig could not be null");
}
this.defaultConfig = mainConfigurationFile;
this.defaults = new Properties();
this.defaults.put(ConfigKeys.APPLICATION_PATH, appPath);
this.defaults.put(ConfigKeys.DEFAULT_CONFIG, mainConfigurationFile);
SystemGlobals.loadDefaults();
this.installation = new Properties();
this.installationConfig = getVariableValue(ConfigKeys.INSTALLATION_CONFIG);
for (Iterator iter = additionalDefaultsList.iterator(); iter.hasNext(); ) {
loadAdditionalDefaults((String) iter.next());
}
if (new File(this.installationConfig).exists()) {
loadAdditionalDefaults(this.installationConfig);
}
}
use of java.security.InvalidParameterException in project robovm by robovm.
the class BaseKeyGenerator method engineInit.
protected void engineInit(int keySize, SecureRandom random) {
try {
if (random == null) {
random = new SecureRandom();
}
engine.init(new KeyGenerationParameters(random, keySize));
uninitialised = false;
} catch (IllegalArgumentException e) {
throw new InvalidParameterException(e.getMessage());
}
}
use of java.security.InvalidParameterException in project robovm by robovm.
the class OpenSSLCipher method engineInitInternal.
private void engineInitInternal(int opmode, Key key, byte[] iv, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
if (opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE) {
encrypting = true;
} else if (opmode == Cipher.DECRYPT_MODE || opmode == Cipher.UNWRAP_MODE) {
encrypting = false;
} else {
throw new InvalidParameterException("Unsupported opmode " + opmode);
}
if (!(key instanceof SecretKey)) {
throw new InvalidKeyException("Only SecretKey is supported");
}
final byte[] encodedKey = key.getEncoded();
if (encodedKey == null) {
throw new InvalidKeyException("key.getEncoded() == null");
}
checkSupportedKeySize(encodedKey.length);
final long cipherType = NativeCrypto.EVP_get_cipherbyname(getCipherName(encodedKey.length, mode));
if (cipherType == 0) {
throw new InvalidAlgorithmParameterException("Cannot find name for key length = " + (encodedKey.length * 8) + " and mode = " + mode);
}
final int ivLength = NativeCrypto.EVP_CIPHER_iv_length(cipherType);
if (iv == null && ivLength != 0) {
iv = new byte[ivLength];
if (encrypting) {
if (random == null) {
random = new SecureRandom();
}
random.nextBytes(iv);
}
} else if (iv != null && iv.length != ivLength) {
throw new InvalidAlgorithmParameterException("expected IV length of " + ivLength);
}
this.iv = iv;
if (supportsVariableSizeKey()) {
NativeCrypto.EVP_CipherInit_ex(cipherCtx.getContext(), cipherType, null, null, encrypting);
NativeCrypto.EVP_CIPHER_CTX_set_key_length(cipherCtx.getContext(), encodedKey.length);
NativeCrypto.EVP_CipherInit_ex(cipherCtx.getContext(), 0, encodedKey, iv, encrypting);
} else {
NativeCrypto.EVP_CipherInit_ex(cipherCtx.getContext(), cipherType, encodedKey, iv, encrypting);
}
// OpenSSL only supports PKCS5 Padding.
NativeCrypto.EVP_CIPHER_CTX_set_padding(cipherCtx.getContext(), padding == Padding.PKCS5PADDING);
modeBlockSize = NativeCrypto.EVP_CIPHER_CTX_block_size(cipherCtx.getContext());
calledUpdate = false;
}
Aggregations