List of usage examples for javax.crypto Cipher getMaxAllowedKeyLength
public static final int getMaxAllowedKeyLength(String transformation) throws NoSuchAlgorithmException
From source file:org.apache.nifi.security.util.crypto.CipherUtility.java
public static boolean isUnlimitedStrengthCryptoSupported() { try {//from w w w . j a v a2 s . c o m return (Cipher.getMaxAllowedKeyLength("AES") > DEFAULT_MAX_ALLOWED_KEY_LENGTH); } catch (NoSuchAlgorithmException e) { return false; } }
From source file:org.apache.pdfbox.encryption.TestSymmetricKeyEncryption.java
/** * {@inheritDoc}/*www . j a va 2 s .co m*/ */ @Override protected void setUp() throws Exception { testResultsDir.mkdirs(); if (Cipher.getMaxAllowedKeyLength("AES") != Integer.MAX_VALUE) { // we need strong encryption for these tests fail("JCE unlimited strength jurisdiction policy files are not installed"); } permission = new AccessPermission(); permission.setCanAssembleDocument(false); permission.setCanExtractContent(false); permission.setCanExtractForAccessibility(true); permission.setCanFillInForm(false); permission.setCanModify(false); permission.setCanModifyAnnotations(false); permission.setCanPrint(true); permission.setCanPrintDegraded(false); permission.setReadOnly(); }
From source file:org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.java
private static void logIfStrongEncryptionMissing() { try {//from ww w. j a v a 2s.c o m if (Cipher.getMaxAllowedKeyLength("AES") != Integer.MAX_VALUE) { LOG.warn("JCE unlimited strength jurisdiction policy files are not installed"); } } catch (NoSuchAlgorithmException ex) { } }
From source file:org.eclipse.che.api.crypt.server.JCEEncryptTextService.java
@Override public boolean isActive() { try {/*from w ww .j av a 2 s .c o m*/ final int keyMaxLength = Cipher.getMaxAllowedKeyLength(this.cipher); boolean active = (keyMaxLength >= this.keySize); if (active) { LOG.debug("Encryption scheme {} enabled - max. allowed keysize={}", this.toString(), keyMaxLength); } else { LOG.debug("Encryption scheme {} disabled - max. allowed keysize={}", this.toString(), keyMaxLength); } return active; } catch (final NoSuchAlgorithmException e) { // cipher is not available LOG.debug("Encryption scheme {} disabled - algorithm is not available", this.toString()); return false; } }
From source file:org.jenkinsci.plugins.relution_publisher.configuration.jobs.ArtifactPublisher.java
private void logKeyLengthInformation(final Log log) { try {// ww w .j a v a 2 s. c om final int maxKeyLength = Cipher.getMaxAllowedKeyLength("AES"); final String value = (maxKeyLength < Integer.MAX_VALUE) ? String.valueOf(maxKeyLength) : "Unrestricted"; log.write(this, "Max. allowed key length: %s", value); } catch (final NoSuchAlgorithmException e) { log.write(this, "Max. allowed key length: <error>"); } this.testDHKeypairSize(log, 1024); this.testDHKeypairSize(log, 2048); this.testDHKeypairSize(log, 4096); log.write(); }
From source file:org.openhab.binding.loxone.internal.core.LxWsSecurityToken.java
private boolean initialize() { try {/* w w w . j a v a 2 s . c o m*/ encryptionReady = false; tokenRefreshRetryCount = TOKEN_REFRESH_RETRY_COUNT; if (Cipher.getMaxAllowedKeyLength("AES") < 256) { return setError(LxOfflineReason.INTERNAL_ERROR, "Enable Java cryptography unlimited strength (see binding doc)."); } // generate a random key for the session KeyGenerator aesKeyGen = KeyGenerator.getInstance("AES"); aesKeyGen.init(256); aesKey = aesKeyGen.generateKey(); // generate an initialization vector secureRandom = new SecureRandom(); secureRandom.nextBytes(initVector); IvParameterSpec ivSpec = new IvParameterSpec(initVector); // initialize aes cipher for command encryption aesEncryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); aesEncryptCipher.init(Cipher.ENCRYPT_MODE, aesKey, ivSpec); // initialize aes cipher for response decryption aesDecryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); aesDecryptCipher.init(Cipher.DECRYPT_MODE, aesKey, ivSpec); // get token value from configuration storage token = (String) configuration.get(SETTINGS_TOKEN); logger.debug("[{}] Retrieved token value: {}", debugId, token); } catch (InvalidParameterException e) { return setError(LxOfflineReason.INTERNAL_ERROR, "Invalid parameter: " + e.getMessage()); } catch (NoSuchAlgorithmException e) { return setError(LxOfflineReason.INTERNAL_ERROR, "AES not supported on platform."); } catch (InvalidKeyException | NoSuchPaddingException | InvalidAlgorithmParameterException e) { return setError(LxOfflineReason.INTERNAL_ERROR, "AES cipher initialization failed."); } return true; }
From source file:org.oscarehr.hospitalReportManager.SFTPConnector.java
/** * Given the absolute path of an encrypted file, decrypt the file using the specified AES key at the top. Return the * string value of the decrypted file./*from www .j a va 2 s. c o m*/ * * @param fullPath * @return * @throws Exception */ public static String decryptFile(String fullPath) throws Exception { logger.debug("About to decrypt: " + fullPath); File encryptedFile = new File(fullPath); if (!encryptedFile.exists()) { throw new Exception("Could not find file '" + fullPath + "' to decrypt."); } //get the bytes of the file in an array int fileLength = (int) encryptedFile.length(); byte[] fileInBytes = new byte[fileLength]; FileInputStream fin = new FileInputStream(encryptedFile); try { fin.read(fileInBytes); } finally { fin.close(); } //the provided key is 32 characters long string hex representation of a 128 hex key, get the 128-bit hex bytes byte keyBytes[] = toHex(OscarProperties.getInstance().getProperty("OMD_HRM_DECRYPTION_KEY")); SecretKeySpec key = new SecretKeySpec(keyBytes, "AES"); int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE"); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decode = cipher.doFinal(fileInBytes); return new String(decode); }
From source file:org.texai.x509.X509Utils.java
/** Returns the maximum key length allowed by the ciphers on this JVM, which depends on whether the unlimited * strength encryption policy jar files have been downloaded and installed. * * @return the maximum allowed key size/*from ww w . j a v a 2s.c om*/ * @throws NoSuchAlgorithmException when the encryption algorithm cannot be found */ public static int getMaxAllowedKeyLength() throws NoSuchAlgorithmException { return Cipher.getMaxAllowedKeyLength("AES"); }
From source file:t3si_server.AES.java
public static void print() throws NoSuchAlgorithmException { int length = Cipher.getMaxAllowedKeyLength("AES"); System.out.println(length);//prints the max key length }