List of usage examples for org.apache.commons.codec.binary Base64 Base64
public Base64()
From source file:com.arm.connector.bridge.core.Utils.java
static public PublicKey createPublicKeyFromPEM(ErrorLogger logger, String pem, String algorithm) { try {//w w w. j a va 2 s. co m String temp = Utils.escapeChars(pem); String publicKeyPEM = temp.replace("-----BEGIN PUBLIC KEY-----", ""); publicKeyPEM = publicKeyPEM.replace("-----END PUBLIC KEY-----", ""); // DEBUG //logger.info("createPublicKeyFromPEM: " + publicKeyPEM); Base64 b64 = new Base64(); byte[] decoded = b64.decode(publicKeyPEM); X509EncodedKeySpec spec = new X509EncodedKeySpec(decoded); KeyFactory kf = KeyFactory.getInstance(algorithm); return kf.generatePublic(spec); } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { // exception caught logger.warning("createPublicKeyFromPEM: Exception during public key gen", ex); } return null; }
From source file:com.ah.ui.actions.home.clientManagement.service.CertificateGenSV.java
public static String certificateGenereate(boolean enableClient, String customerId, String hmId, String domain, String caType, String certType, BeRootCADTO data, HMServicesSettings bo) throws Exception { String rt = ""; String enableOnboard = ""; String enableCid = ""; // String useCustomCert = ""; String cerDic = BeAdminCentOSTools.AH_CERTIFICAT_PFEFIX + domain + BeAdminCentOSTools.AH_CERTIFICATE_HOME + File.separator;//from w ww . j a v a2s . c o m String csrf = data.getFileName() + ".csr"; if (enableClient == true) { enableOnboard = "1"; } else { enableOnboard = "0"; } // if(useCusCert == true){ // useCustomCert = "1"; // }else{ // useCustomCert = "0"; // } try { IResponseFromMDM res = new ResponseFromMDMImpl(); CertificateGenSV cerSV = new CertificateGenSV(); String clientm = cerSV.transEnableClientManageToXML(customerId, hmId, enableOnboard); ResponseModel resm = res.sendInfoToMDM(getUrl() + ENABLE_URI, clientm); if (enableClient == true) { OnBoardCaEBO onb = null; if (HttpStatus.SC_OK == resm.getResponseCode()) { onb = cerSV.transResponseToOnBoardCa(resm); } else { return MgrUtil.getUserMessage("home.clientManagement.enable.ca", new String[] { hmId, customerId }); } //save the apikey to the database bo.setApiKey(onb.getApiKey()); Base64 b64 = new Base64(); byte[] content = b64.decode(onb.getCertPayload()); cerSV.writeFile(cerDic + CertificateGenSV.ONBOARD_CA, new String(content)); boolean isSuccess = HmBeAdminUtil.createServerCSR(data); if (isSuccess == true) { String csrContent = cerSV.readFile(cerDic + csrf); String csrTem = cerSV.transCsrCertificateToXML(customerId, hmId, certType, csrContent); ResponseModel csrRes = res.sendInfoToMDM(getUrl() + CERT_URI, csrTem); if (HttpStatus.SC_OK != csrRes.getResponseCode()) { return MgrUtil.getUserMessage("home.clientManagement.enable.server", new String[] { hmId, customerId }); } SignedCertificateEBO sce = cerSV.transResponseToSignedCertificate(csrRes); byte[] sc = b64.decode(sce.getCertPayload()); cerSV.writeFile(cerDic + CertificateGenSV.SERVER_CRT, new String(sc)); boolean result = generatePfxCertificate(cerDic); if (!result) { return MgrUtil.getUserMessage("home.clientManagement.enable.pfx", new String[] { hmId, customerId }); } } } return rt; } catch (IOException e) { throw new IOException(); } catch (Exception e) { log.error("certificateGenerate()", "Error when generate the certificate", e); throw new Exception(); //e.printStackTrace(); } }
From source file:com.xtc.controller.UserController.java
@RequestMapping("/image/upload") public @ResponseBody Map<String, Object> selectTwo(ModelMap map, String file, String mobile) throws IOException { Map<String, Object> mapRtn = new HashMap<String, Object>(); try {//from w w w . ja va 2 s .c o m byte[] by = new Base64().decode(file); ByteArrayInputStream is = new ByteArrayInputStream(by); // String avatar = this.fileService.uploadImage(is); if (avatar != null) { boolean user = us.updateavatar(avatar, mobile); mapRtn.put(RestDto.RESULT, user); mapRtn.put("avatar", avatar); } else { mapRtn.put(RestDto.RESULT, false); } } catch (Exception e) { mapRtn.put(RestDto.RESULT, false); } return mapRtn; }
From source file:com.viettel.hqmc.DAO.FeeDao.java
public String onDeny() { FeeDAOHE rdhe = new FeeDAOHE(); Base64 decoder = new Base64(); Long paymentInfoId = Long.parseLong(getRequest().getParameter("paymentInfoId")); String commentReject = null;/*from w w w.j av a 2s .c om*/ try { commentReject = new String( decoder.decode(getRequest().getParameter("commentReject").replace("_", "+").getBytes()), "UTF-8"); } catch (UnsupportedEncodingException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // Logger.getLogger(FeeDao.class.getName()).log(Level.SEVERE, null, ex.getMessage()); } boolean bReturn = rdhe.denyFee(paymentInfoId, commentReject); List resultMessage = new ArrayList(); if (bReturn) { resultMessage.add("1"); resultMessage.add("Lu d liu thnh cng"); } else { resultMessage.add("3"); resultMessage.add("Lu d liu khng thnh cng"); } jsonDataGrid.setItems(resultMessage); return GRID_DATA; }
From source file:com.globalsight.everest.usermgr.UserLdapHelper.java
/** * Encypt the passwd using md5. The return value will be suffic with the * {MD5}/*from w ww .j av a 2 s .c om*/ * * @param passwd * @return */ static String encyptMD5Password(String passwd) { try { byte[] md5Msg = MessageDigest.getInstance(LDAP_PWD_MD5).digest(passwd.getBytes()); return LDAP_PREFIX_MD5 + new String(new Base64().encode(md5Msg)); } catch (NoSuchAlgorithmException e) { CATEGORY.error("The system didn't support the Md5 ALGORITHM", e); } return passwd; }
From source file:com.mercatis.lighthouse3.commons.commons.XmlMuncher.java
/** * This static helper method converts XML Schema <code>binary</code> format * in a Java byte array./* ww w . j a va 2 s . c o m*/ * * @param binary the XML Schema binary data to convert * @return the byte array or null if the binary format passed is not valid * base64. */ public static byte[] xmlBinaryToByteArray(String binary) { return new Base64().decode(binary.getBytes()); }
From source file:com.globalsight.everest.usermgr.UserLdapHelper.java
/** * Encypt the passwd using sha. The return value will be suffic with the * {SHA}//from ww w .j ava2s. c o m * * @param passwd * @return */ static String encyptShaPassword(String passwd) { try { byte[] shaMsg = MessageDigest.getInstance(LDAP_PWD_SHA).digest(passwd.getBytes()); return LDAP_PREFIX_SHA + new String(new Base64().encode(shaMsg)); } catch (NoSuchAlgorithmException e) { CATEGORY.error("The system didn't support the Sha ALGORITHM", e); } return passwd; }
From source file:com.mercatis.lighthouse3.commons.commons.XmlMuncher.java
/** * This static helper method converts text data in XML Schema <code>binary</code> format * in a Java char array./* w ww .ja v a2 s. co m*/ * * @param binary the XML Schema binary data to convert * @return the char array or null if the binary format passed is not valid * base64. */ public static char[] xmlBinaryToCharArray(String binary) { byte[] bytes = new Base64().decode(binary.getBytes()); return new String(bytes).toCharArray(); }
From source file:com.ah.ui.actions.home.clientManagement.service.CertificateGenSV.java
public boolean signCsrByClientCA(String domain, String customerId, String hmId, String csrf) { String cerDic = BeAdminCentOSTools.AH_CERTIFICAT_PFEFIX + domain + BeAdminCentOSTools.AH_CERTIFICATE_HOME + File.separator;//w w w . j a v a2s . c o m boolean isSuccess = false; IResponseFromMDM res = new ResponseFromMDMImpl(); Base64 b64 = new Base64(); try { String csrContent = readFile(cerDic + csrf + ".csr"); String csrTem = transCsrCertificateToXML(customerId, hmId, "AuthServer", csrContent); ResponseModel csrRes = res.sendInfoToMDM(getUrl() + CERT_URI, csrTem); SignedCertificateEBO sce = transResponseToSignedCertificate(csrRes); byte[] sc = b64.decode(sce.getCertPayload()); writeFile(cerDic + csrf + ".crt", new String(sc)); isSuccess = true; } catch (Exception e) { log.error(e.getMessage(), "error happened when sign csr by client CA.", e); } return isSuccess; }
From source file:com.baracuda.piepet.nexusrelease.nexus.StageClient.java
/** * Add the BASIC Authentication header to the HTTP connection. * /*from w w w . jav a 2 s . co m*/ * @param conn the HTTP URL Connection */ private void addAuthHeader(URLConnection conn) { // java.net.Authenticator is brain damaged as it is global and no way to delegate for just one server... try { String auth = username + ":" + password; // there is a lot of debate about password and non ISO-8859-1 characters... // see https://bugzilla.mozilla.org/show_bug.cgi?id=41489 // Base64 adds a trailing newline - just strip it as whitespace is illegal in Base64 String encodedAuth = new Base64().encodeToString(auth.getBytes("ISO-8859-1")).trim(); conn.setRequestProperty("Authorization", "Basic " + encodedAuth); log.debug("Encoded Authentication is: " + encodedAuth); } catch (UnsupportedEncodingException ex) { String msg = "JVM does not conform to java specification. Mandatory CharSet ISO-8859-1 is not available."; log.error(msg); throw new RuntimeException(msg, ex); } }