public static String decodeUTF8(String text) { try { return URLDecoder.decode(text, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new UnexpectedException(e); } }
public static String encodeUTF8(String text) { try { return URLEncoder.encode(text, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new UnexpectedException(e); } }
public static DOMImplementationRegistry getDomImplRegistry() { try { return DOMImplementationRegistry.newInstance(); } catch (ClassNotFoundException e) { throw new UnexpectedException(e); } catch (InstantiationException e) { throw new UnexpectedException(e); } catch (IllegalAccessException e) { throw new UnexpectedException(e); } }
public static URL newUrl(String url) { try { return new URL(url); } catch (MalformedURLException e) { throw new UnexpectedException(e); } }
public static byte[] gzip(byte[] data) { try { ByteArrayOutputStream buf = new ByteArrayOutputStream(); GZIPOutputStream os = new GZIPOutputStream(buf); os.write(data); os.close(); return buf.toByteArray(); } catch (IOException e) { throw new UnexpectedException(e); } }
public static byte[] gzip(byte[] data) { try { ByteArrayOutputStream buf = new ByteArrayOutputStream(); GZIPOutputStream os = new GZIPOutputStream(buf); os.write(data); os.close(); return buf.toByteArray(); } catch (IOException e) { throw new UnexpectedException(e); } }
public static byte[] gzip(byte[] data) { try { ByteArrayOutputStream buf = new ByteArrayOutputStream(); GZIPOutputStream os = new GZIPOutputStream(buf); os.write(data); os.close(); return buf.toByteArray(); } catch (IOException e) { throw new UnexpectedException(e); } }
public static DocumentBuilder getDocumentBuilder(boolean namespaceAware) { try { return getDocumentBuilderFactory(namespaceAware).newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new UnexpectedException(e); } }
public static DocumentBuilder getDocumentBuilder(boolean namespaceAware) { try { return getDocumentBuilderFactory(namespaceAware).newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new UnexpectedException(e); } }
protected void readX509Key( String algorithm, byte[] encodedKey) throws InvalidKeyException { try { KeyFactory kf = KeyFactory.getInstance(algorithm); key = kf.generatePublic(new X509EncodedKeySpec(encodedKey)); } catch (NoSuchAlgorithmException e) { throw new UnexpectedException(e); } catch (InvalidKeySpecException e) { throw new InvalidKeyException(e); } } }
@Override public byte[] pbkdf2(DigestAlgorithm digestAlgorithms, char[] password, int iterations, byte[] salt, int keyLen) { try { KeySpec keySpec = new PBEKeySpec(password, salt, iterations, keyLen); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmac" + digestAlgorithms.name()); return keyFactory.generateSecret(keySpec).getEncoded(); } catch (NoSuchAlgorithmException e) { throw new UnexpectedException(e); } catch (InvalidKeySpecException e) { throw new IllegalArgumentException("Invalid key parameters", e); } }
protected void readPKCS8Key( String algorithm, byte[] encodedKey ) throws InvalidKeyException { try { KeyFactory kf = KeyFactory.getInstance(algorithm); key = kf.generatePrivate(new PKCS8EncodedKeySpec(encodedKey)); } catch (NoSuchAlgorithmException e) { throw new UnexpectedException(e); } catch (InvalidKeySpecException e) { throw new InvalidKeyException(e); } } }
@Nullable @Override public EncodedKey getEncoded() { try { return getEncoded(SERIALIZED); } catch (InvalidKeyEncodingException e) { throw new UnexpectedException(e); } }
@NotNull @Override public RSAKeyPair generateRSAKeyPair(int keySize) { try { KeyPairGenerator rsaKeyGen = KeyPairGenerator.getInstance(AsymmetricAlgorithm.RSA.getJceId()); rsaKeyGen.initialize(keySize); return new JCERSAKeyPair(this, rsaKeyGen.generateKeyPair()); } catch (NoSuchAlgorithmException e) { throw new UnexpectedException(e); } }
@NotNull @Override public AESKey generateAESKey(AESKeyLen keySize) { try { KeyGenerator aesKeyGen = KeyGenerator.getInstance(SymmetricAlgorithm.AES.getJceId()); aesKeyGen.init(keySize.getLenBits()); return new JCEAESKey(this, aesKeyGen.generateKey()); } catch (NoSuchAlgorithmException e) { throw new UnexpectedException(e); } }
@Override public Digest digest(DigestAlgorithm alg) { try { return new JCEDigest(MessageDigest.getInstance(alg.getJceId())); } catch (NoSuchAlgorithmException e) { throw new UnexpectedException(e); } }
@Override public byte[] serialize() { try { return getEncoded(EncodedKey.Format.SERIALIZED).getEncodedKey(); } catch (InvalidKeyEncodingException e) { throw new UnexpectedException(e); } }
public CHRegion findDefaultCHRegion() throws HttpException { for (CHRegion region : findAllCHRegions()) { if (region.isDefaultRegion()) { return region; } } throw new UnexpectedException("No default mule version found"); }
public byte[] toByteArray() { try { final ByteArrayDataOutputStream buf = new ByteArrayDataOutputStream(); toByteArray(buf); buf.close(); return buf.toByteArray(); } catch (IOException e) { throw new UnexpectedException(e); } }
private byte[] agreeDHKey(DHPrivateKey dhPrivateKey, DHPublicKey dhPublicKey) throws InvalidKeyException { try { KeyAgreement ka = KeyAgreement.getInstance("DH"); ka.init(((JCEDHPrivateKey) dhPrivateKey).getJCEPrivateKey()); ka.doPhase(((JCEDHPublicKey) dhPublicKey).getJCEPublicKey(), true); return ka.generateSecret(); } catch (NoSuchAlgorithmException e) { throw new UnexpectedException(e); } } }