} catch(DecoderException de) { System.err.println("Error decoding key " + keyString); de.printStackTrace(); return; } catch(IOException io) {
} catch(DecoderException de) { System.err.println("Error decoding key " + keyString); de.printStackTrace(); return; } catch(IOException io) {
encoded = decodeHex(data.toCharArray()); } catch (DecoderException e) { e.printStackTrace(); return null;
@Override public Object resolve(Context c, Map<String, String[]> parameters, Map<String, InputStream> dataStreams) throws JSONException { String obj = getObjAsString(c, parameters, dataStreams); if (obj == null) return null; try { return new String(Hex.decodeHex(obj.toCharArray())); } catch (DecoderException e) { e.printStackTrace(); return null; } }
String s = "=?ISO-8859-2?Q?Zesp=F3=B3_Gmaila"; Pattern p = Pattern.compile("=\\?([a-zA-Z0-9\\-]+)\\?Q\\?"); //For detecting the encoding Matcher m = p.matcher(s); if( m.find() ) { String encoding = m.group(1); String target = s.replaceAll( p.toString(), ""); //Remove the encoding header QuotedPrintableCodec qpc = new QuotedPrintableCodec(encoding); try { System.out.println(qpc.decode(target)); // prints "Zespół_Gmaila" } catch (DecoderException e) { e.printStackTrace(); } }
try { String arg = "b74420f5a4d9abfd2072c9d936dd53e2de2aa790822ad1608807bda3e176b335c51902ca2177824198181ce8bea85de132aaea1104fd043e4ad2c0af705bda966b5d2f92a6ab5170d161eb1e8f7a6b1d5fba673f8a4dcebe55407ef9707782c91b17527af820a2c3a3b586341ae54ef03739074d4738e3ff35257bdfb9233c53"; String message = "plain text"; byte[] publicBytes = org.apache.commons.codec.binary.Hex.decodeHex(arg.toCharArray()); BigInteger modulus = new BigInteger(1, publicBytes); BigInteger publicExponent = BigInteger.valueOf(65537L); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(modulus, publicExponent); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PublicKey pubKey = keyFactory.generatePublic(keySpec); try { // decrypts the message byte[] encryptedBytes = null; Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, pubKey); encryptedBytes = cipher.doFinal(message.getBytes()); System.out.println( "Encrypted text : "+ convertToHexString(encryptedBytes)); } catch (BadPaddingException | IllegalBlockSizeException | InvalidKeyException | NoSuchPaddingException | NoSuchAlgorithmException k) { k.printStackTrace(); } } catch (DecoderException e) { e.printStackTrace(); }
public static Object deserializeStr(String hexStr) { try { if (StringUtils.isEmpty(hexStr)) { return null; } return deserialize(Hex.decodeHex(hexStr.toCharArray())); } catch (DecoderException e) { e.printStackTrace(); } return null; }
public static Object deserializeStr(String hexStr) { try { if (StringUtils.isEmpty(hexStr)) { return null; } return deserialize(Hex.decodeHex(hexStr.toCharArray())); } catch (DecoderException e) { e.printStackTrace(); } return null; }
public static void main(String[] args) { QuotedPrintableCodec a = new QuotedPrintableCodec("UTF-8"); try { System.out.println(a.decode("TestBody=CE=93")); // prints "TestBodyΓ" } catch (DecoderException e) { e.printStackTrace(); } }
private static String parseToken(String networkSection, String tokenName) { if (hasToken(networkSection, tokenName)) { List<String> tokenLines = tokenLines(networkSection, tokenName); String key = tokenLines.get(0).split("=", 2)[1]; if (tokenName.equals("ssid") || tokenName.equals("psk") || tokenName.startsWith("wep_key")) { if (key.startsWith("\"")) { key = key.replaceAll("^\"", "").replaceAll("\"$", ""); } else { try { key = new String(Hex.decodeHex(key.toCharArray())); } catch (DecoderException e) { e.printStackTrace(); } } } return key; } return ""; } }
e.printStackTrace(); return null;
/** * * @param password * @return * @throws EncrpyException */ public static String decodePassword(String password)throws EncrpyException{ ConfigManager manager = ConfigManager.getInstance(); String encrypeType = manager.getConfigValue("encrpytype", "NONE"); if (encrypeType.equals("MD5")) { throw new EncrpyException("MD5算法不能解密"); } else if (encrypeType.equals("BASE64")){ Base64 base = new Base64(); return base.getDecodeBase64(password); }else if(encrypeType.equals("HEX")){ try { return Hex.decodeHex(password.toCharArray()).toString(); } catch (DecoderException e) { e.printStackTrace(); } } return password; } }
/** * * @param password * @return * @throws EncrpyException */ public static String decodePassword(String password)throws EncrpyException{ ConfigManager manager = ConfigManager.getInstance(); String encrypeType = manager.getConfigValue("encrpytype", "NONE"); if (encrypeType.equals("MD5")) { throw new EncrpyException("MD5算法不能解密"); } else if (encrypeType.equals("BASE64")){ Base64 base = new Base64(); return base.getDecodeBase64(password); }else if(encrypeType.equals("HEX")){ try { return Hex.decodeHex(password.toCharArray()).toString(); } catch (DecoderException e) { e.printStackTrace(); } } return password; } }
/** * converts the passed in String to an equivalent object * @param pStr * @return Object */ public Object toObject(String pStr){ String decoded = null; try{ decoded = decoder.decode(pStr); }catch(DecoderException ex){ ex.printStackTrace(); throw new TranslationException(ex.getMessage()); } return decoded; }
private static void lockAll(Sheet s, XSSFWorkbook workbookx){ String password= "abcd"; byte[] pwdBytes = null; try { pwdBytes = Hex.decodeHex(password.toCharArray()); } catch (DecoderException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } XSSFSheet sheet = ((XSSFSheet)s); removePivot(s,workbookx); sheet.lockDeleteColumns(); sheet.lockDeleteRows(); sheet.lockFormatCells(); sheet.lockFormatColumns(); sheet.lockFormatRows(); sheet.lockInsertColumns(); sheet.lockInsertRows(); sheet.getCTWorksheet().getSheetProtection().setPassword(pwdBytes); for(byte pwdChar :pwdBytes){ System.out.println(">>> Sheet protected with '" + pwdChar + "'"); } sheet.enableLocking(); workbookx.lockStructure(); }