List of usage examples for org.bouncycastle.util.encoders Base64 encode
public static byte[] encode(byte[] data)
From source file:ataraxis.crypt.AtaraxisHeaderCreator.java
License:Open Source License
/** * AtaraxisHeaderCreator create a new random initial Vector and makes all ready * to store this new Header to a File. You could use this for mulitple files, but we * strongly suggest that you create for every file a new Header. *//*from w w w. j a v a 2 s. c o m*/ public AtaraxisHeaderCreator() { LOGGER.debug("Start with AtaraxisHeaderCreator()"); random = new SecureRandom(); ivBytes = new byte[16]; random.nextBytes(ivBytes); headerContent = "AtaraxiS Header Start\n" + "HeaderVersion: " + headerVersion + "\n" + "IV: " + new String(Base64.encode(ivBytes)) + "\n" + "AtaraxiS Header End\n\n"; LOGGER.info("AtaraxisHeaderCreator() is ready to use"); }
From source file:be.fedict.eid.dss.sp.bean.SPBean.java
License:Open Source License
public void setPostRequest(ServletRequest request) { this.request = request; HttpServletRequest httpServletRequest = (HttpServletRequest) request; byte[] document = setRequest(httpServletRequest, "en", "dss-response"); if (null != document) { this.signatureRequest = new String(Base64.encode(document)); httpServletRequest.getSession().setAttribute("SignatureRequest", this.signatureRequest); httpServletRequest.getSession().setAttribute("ContentType", this.contentType); }/* w w w . j av a2 s. com*/ }
From source file:be.fedict.eid.dss.sp.servlet.UploadServlet.java
License:Open Source License
@Override @SuppressWarnings("unchecked") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug("doPost"); String fileName = null;/*w w w .j a v a2s. c om*/ String contentType; byte[] document = null; FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request try { List<FileItem> items = upload.parseRequest(request); if (!items.isEmpty()) { fileName = items.get(0).getName(); // contentType = items.get(0).getContentType(); document = items.get(0).get(); } } catch (FileUploadException e) { throw new ServletException(e); } String extension = FilenameUtils.getExtension(fileName).toLowerCase(); contentType = supportedFileExtensions.get(extension); if (null == contentType) { /* * Unsupported content-type is converted to a ZIP container. */ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); ZipEntry zipEntry = new ZipEntry(fileName); zipOutputStream.putNextEntry(zipEntry); IOUtils.write(document, zipOutputStream); zipOutputStream.close(); fileName = FilenameUtils.getBaseName(fileName) + ".zip"; document = outputStream.toByteArray(); contentType = "application/zip"; } LOG.debug("File name: " + fileName); LOG.debug("Content Type: " + contentType); String signatureRequest = new String(Base64.encode(document)); request.getSession().setAttribute(DOCUMENT_SESSION_ATTRIBUTE, document); request.getSession().setAttribute("SignatureRequest", signatureRequest); request.getSession().setAttribute("ContentType", contentType); response.sendRedirect(request.getContextPath() + this.postPage); }
From source file:bluecrystal.example.web.CreateEnvelope.java
License:Open Source License
private boolean verifySignature(Boolean algSha256, String ret, String filename) throws Exception { MessageDigest hashSum = null; if (algSha256) { hashSum = MessageDigest.getInstance("SHA-256"); logger.debug("Validar assinatura SHA-256"); } else {/* w w w . jav a 2 s .co m*/ hashSum = MessageDigest.getInstance("SHA-1"); logger.debug("Validar assinatura SHA-1"); } hashSum.update(Convert.readFile(filename)); byte[] digestResult = hashSum.digest(); // Base64.Encoder encoder = Base64.getEncoder(); String digestB64 = new String(Base64.encode(digestResult)); return serv.validateSign(ret, digestB64, Convert.asXMLGregorianCalendar(new Date()), false); }
From source file:bluecrystal.example.web.CreateEnvelope.java
License:Open Source License
private int validateSignWithStatus(Boolean algSha256, String ret, String filename) throws Exception { MessageDigest hashSum = null; if (algSha256) { hashSum = MessageDigest.getInstance("SHA-256"); logger.debug("Validar assinatura SHA-256"); } else {//from ww w.ja v a2 s . co m hashSum = MessageDigest.getInstance("SHA-1"); logger.debug("Validar assinatura SHA-1"); } hashSum.update(Convert.readFile(filename)); byte[] digestResult = hashSum.digest(); // Base64.Encoder encoder = Base64.getEncoder(); String digestB64 = new String(Base64.encode(digestResult)); return serv.validateSignWithStatus(ret, digestB64, Convert.asXMLGregorianCalendar(new Date()), false); }
From source file:bluecrystal.service.v1.icpbr.IcpbrServiceImpl.java
License:Open Source License
public String hashSignedAttribADRB10(String origHashB64, Date signingTime, String x509B64) throws Exception { LogDebug("hashSignedAttribSha1: " + "\norigHashB64 (" + origHashB64 + ")" + "\nsigningTime(" + signingTime + ")" + "\nx509B64(" + x509B64 + ")"); try {/*ww w. j a va2s . c o m*/ byte[] origHash = Base64.decode(origHashB64); byte[] x509 = Base64.decode(x509B64); X509Certificate cert = loadCert(x509); byte[] ret = ccServ.hashSignedAttribSha1(origHash, signingTime, cert); return new String(Base64.encode(ret)); } catch (Exception e) { LOG.error("ERRO: ", e); throw e; } }
From source file:bluecrystal.service.v1.icpbr.IcpbrServiceImpl.java
License:Open Source License
public String hashSignedAttribADRB21(String origHashB64, Date signingTime, String x509B64) throws Exception { LogDebug("hashSignedAttribSha256: " + "\norigHashB64 (" + origHashB64 + ")" + "\nsigningTime(" + signingTime + ")" + "\nx509B64(" + x509B64 + ")"); try {// w ww .j ava2 s .c om byte[] origHash = Base64.decode(origHashB64); byte[] x509 = Base64.decode(x509B64); X509Certificate cert = loadCert(x509); byte[] ret = ccServ.hashSignedAttribSha256(origHash, signingTime, cert); return new String(Base64.encode(ret)); } catch (Exception e) { LOG.error("ERRO: ", e); throw e; } }
From source file:bluecrystal.service.v1.icpbr.IcpbrServiceImpl.java
License:Open Source License
public String extractSignature(String signB64) throws Exception { LogDebug("extractSignature: " + "\nsignB64 (" + signB64 + ")"); try {//from ww w . jav a 2 s. com byte[] sign = Base64.decode(signB64); byte[] ret = ccServ.extractSignature(sign); return new String(Base64.encode(ret)); } catch (Exception e) { LOG.error("ERRO: ", e); throw e; } }
From source file:bluecrystal.service.v1.icpbr.IcpbrServiceImpl.java
License:Open Source License
public String composeEnvelopeADRB10(String signB64, String x509B64, String origHashB64, Date signingTime) throws Exception { LogDebug("composeBodySha1: " + "\nsignB64 (" + signB64 + ")" + "\nx509B64 (" + x509B64 + ")" + "\norigHashB64 (" + origHashB64 + ")" + "\nsigningTime (" + signingTime + ")"); try {/*from w ww . j a v a2s . co m*/ byte[] sign = Base64.decode(signB64); byte[] origHash = Base64.decode(origHashB64); byte[] x509 = Base64.decode(x509B64); X509Certificate cert = loadCert(x509); byte[] ret = ccServ.composeBodySha1(sign, cert, origHash, signingTime); byte[] hashSa = ccServ.hashSignedAttribSha1(origHash, signingTime, cert); if (!verify.verify(NDX_SHA1, ccServ.calcSha1(hashSa), sign, cert)) { throw new InvalidSigntureException(); } return new String(Base64.encode(ret)); } catch (Exception e) { LOG.error("ERRO: ", e); throw e; } }
From source file:bluecrystal.service.v1.icpbr.IcpbrServiceImpl.java
License:Open Source License
public String composeEnvelopeADRB21(String signB64, String x509B64, String origHashB64, Date signingTime) throws Exception { LogDebug("composeBodySha256: " + "\nsignB64 (" + signB64 + ")" + "\nx509B64 (" + x509B64 + ")" + "\norigHashB64 (" + origHashB64 + ")" + "\nsigningTime (" + signingTime + ")"); try {// w ww . ja va 2 s . com byte[] sign = Base64.decode(signB64); byte[] origHash = Base64.decode(origHashB64); byte[] x509 = Base64.decode(x509B64); X509Certificate cert = loadCert(x509); byte[] hashSa = ccServ.hashSignedAttribSha256(origHash, signingTime, cert); if (!verify.verify(NDX_SHA256, ccServ.calcSha256(hashSa), sign, cert)) { throw new InvalidSigntureException(); } byte[] ret = ccServ.composeBodySha256(sign, cert, origHash, signingTime); return new String(Base64.encode(ret)); } catch (Exception e) { LOG.error("ERRO: ", e); throw e; } }