List of usage examples for javax.crypto NoSuchPaddingException getLocalizedMessage
public String getLocalizedMessage()
From source file:jfs.sync.encryption.AbstractEncryptedStorageAccess.java
protected String getEncryptedFileName(String relativePath, String pathElement) { if (encryptionCache.containsKey(relativePath+getSeparator()+pathElement)) { return encryptionCache.get(relativePath+getSeparator()+pathElement); } // if//from ww w .ja v a2 s.c o m try { Cipher encrypter = SecurityUtils.getCipher(getCipherSpec(), Cipher.ENCRYPT_MODE, getCredentials(relativePath)); byte[] bytes = encrypter.doFinal(getEncodedFileName(relativePath, pathElement)); StringBuilder result = new StringBuilder(); int index = 0; int bc = 0; // System.out.print("E: "); for (int i = 0; i<bytes.length; i++) { for (int mask = 128; mask>0; mask = mask>>1) { int bit = ((bytes[i]&mask)==0) ? 0 : 1; // System.out.print(bit); index = (index<<1)+bit; bc++; if (bc==bits) { char code = CODES[index]; result.append(code); bc = 0; index = 0; } // if } // for // System.out.print(" "+bytes[i]+" "); } // for index = index<<(bits-bc); char code = CODES[index]; result.append(code); String resultString = result.toString(); // System.out.println(""); encryptionCache.put(relativePath+getSeparator()+pathElement, resultString); pathElement = resultString; } catch (NoSuchAlgorithmException nsae) { LOG.error("getEncryptedFileName() No Such Algorhithm "+nsae.getLocalizedMessage()); } catch (NoSuchPaddingException nspe) { LOG.error("getEncryptedFileName() No Such Padding "+nspe.getLocalizedMessage()); } catch (InvalidKeyException ike) { LOG.error("getEncryptedFileName() Invalid Key "+ike.getLocalizedMessage()); } catch (ArrayIndexOutOfBoundsException e) { LOG.error("getEncryptedFileName("+pathElement+") ArrayIndexOutOfBoundsException", e); } catch (IllegalBlockSizeException e) { LOG.error("getEncryptedFileName("+pathElement+") IllegalBlockSizeException", e); } catch (BadPaddingException e) { LOG.error("getEncryptedFileName("+pathElement+") BadPaddingException", e); } // try/catch return pathElement; }
From source file:jfs.sync.encryption.AbstractEncryptedStorageAccess.java
protected String getDecryptedFileName(String relativePath, String name) { if (decryptionCache.containsKey(relativePath+getSeparator()+name)) { return decryptionCache.get(relativePath+getSeparator()+name); } // if//from w w w . j av a 2 s. c om try { List<Byte> resultList = new ArrayList<Byte>(); // System.out.print("D: "); int bc = 0; byte value = 0; for (int i = 0; i<name.length(); i++) { char code = name.charAt(i); byte index = reverseCodes[code]; for (int mask = decoding_mask; mask>0; mask = mask>>1) { int bit = (index&mask)==0 ? 0 : 1; // System.out.print(bit); value = (byte) ((value<<1)+bit); bc++; if (bc==8) { // System.out.print(" "+value+" "); resultList.add(value); bc = 0; value = 0; } // if } // for } // for byte[] decodedBytes = new byte[resultList.size()]; int i = 0; for (byte b : resultList) { decodedBytes[i++] = b; } // for // System.out.println(""); Cipher decrypter = SecurityUtils.getCipher(getCipherSpec(), Cipher.DECRYPT_MODE, getCredentials(relativePath)); byte[] decryptedBytes = decrypter.doFinal(decodedBytes); // name = new String(decryptedBytes, "UTF-8"); String decryptedName = getDecodedFileName(relativePath, decryptedBytes); decryptionCache.put(relativePath+getSeparator()+name, decryptedName); name = decryptedName; } catch (NoSuchAlgorithmException nsae) { LOG.error("getDecryptedFileName() No Such Algorhithm "+nsae.getLocalizedMessage()); } catch (NoSuchPaddingException nspe) { LOG.error("getDecryptedFileName() No Such Padding "+nspe.getLocalizedMessage()); } catch (InvalidKeyException ike) { LOG.error("getDecryptedFileName() Invalid Key "+ike.getLocalizedMessage()); } catch (ArrayIndexOutOfBoundsException e) { LOG.error("getDecryptedFileName() ArrayIndexOutOfBoundsException", e); } catch (IllegalBlockSizeException e) { LOG.error("getDecryptedFileName() IllegalBlockSizeException", e); } catch (BadPaddingException e) { LOG.error("getDecryptedFileName() BadPaddingException", e); } // try/catch return name; }