List of usage examples for org.bouncycastle.asn1.pkcs PKCS12PBEParams PKCS12PBEParams
public PKCS12PBEParams(byte[] salt, int iterations)
From source file:org.mailster.core.crypto.MailsterKeyStoreFactory.java
License:Open Source License
public boolean checkCryptoPermission() throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException { LOG.debug("Cryptography permission check"); try {//from w ww . j a v a2 s. co m byte[] iv = new byte[20]; CertificateUtilities.RANDOM.nextBytes(iv); PKCS12PBEParams pbeParams = new PKCS12PBEParams(iv, 1024); String algorithm = "1.2.840.113549.1.12.1.3"; SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm, "BC"); PBEParameterSpec defParams = new PBEParameterSpec(pbeParams.getIV(), pbeParams.getIterations().intValue()); Cipher cipher = Cipher.getInstance(algorithm, "BC"); PBEKeySpec pbeSpec = new PBEKeySpec("testwelcome".toCharArray()); cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), defParams); return true; } catch (InvalidKeyException ex) { cryptoPermissionDenied = true; setErrorMessage(Messages.getString("MailsterKeyStoreFactory.error.vm.crypto.restrictions")); return false; } }