List of usage examples for java.math BigInteger toString
public String toString()
From source file:eu.europa.esig.dss.xades.signature.XAdESBuilder.java
/** * Incorporates the certificate's references as a child of the given parent node. The first element of the {@code X509Certificate} {@code List} MUST be the signing * certificate.//from w w w.j av a2s.co m * * @param signingCertificateDom DOM parent element * @param certificates {@code List} of the certificates to be incorporated */ protected void incorporateCertificateRef(final Element signingCertificateDom, final List<CertificateToken> certificates) { for (final CertificateToken certificate : certificates) { final Element certDom = DSSXMLUtils.addElement(documentDom, signingCertificateDom, XAdES, XADES_CERT); final Element certDigestDom = DSSXMLUtils.addElement(documentDom, certDom, XAdES, XADES_CERT_DIGEST); final DigestAlgorithm signingCertificateDigestMethod = params.getSigningCertificateDigestMethod(); incorporateDigestMethod(certDigestDom, signingCertificateDigestMethod); final InMemoryDocument inMemoryCertificate = new InMemoryDocument(certificate.getEncoded()); incorporateDigestValue(certDigestDom, signingCertificateDigestMethod, inMemoryCertificate); if (params.isEn319132()) { try { final Element issuerSerialDom = DSSXMLUtils.addElement(documentDom, certDom, XAdES, XADES_ISSUER_SERIAL_V2); String name = certificate.getCertificate().getIssuerX500Principal().getName(); IssuerAndSerialNumber issuerAndSerial = new IssuerAndSerialNumber(new X500Name(name), certificate.getCertificate().getSerialNumber()); byte[] issuer = Base64.encodeBase64(issuerAndSerial.getEncoded()); DSSXMLUtils.setTextNode(documentDom, issuerSerialDom, new String(issuer)); } catch (IOException e) { throw new RuntimeException(e); } } else { final Element issuerSerialDom = DSSXMLUtils.addElement(documentDom, certDom, XAdES, XADES_ISSUER_SERIAL); final Element x509IssuerNameDom = DSSXMLUtils.addElement(documentDom, issuerSerialDom, XMLNS, DS_X509_ISSUER_NAME); final String issuerX500PrincipalName = certificate.getIssuerX500Principal().getName(); DSSXMLUtils.setTextNode(documentDom, x509IssuerNameDom, issuerX500PrincipalName); final Element x509SerialNumberDom = DSSXMLUtils.addElement(documentDom, issuerSerialDom, XMLNS, DS_X509_SERIAL_NUMBER); final BigInteger serialNumber = certificate.getSerialNumber(); final String serialNumberString = new String(serialNumber.toString()); DSSXMLUtils.setTextNode(documentDom, x509SerialNumberDom, serialNumberString); } } }
From source file:org.wso2.carbon.identity.certificateauthority.endpoint.scep.ScepEndpoint.java
private List<X509Certificate> doGetCert(X509Name principal, BigInteger serial) { try {// ww w . j a v a 2s.co m X509Certificate certificate = scepServices.getCertificate(serial.toString()); if (certificate != null) { return Collections.singletonList(certificate); } } catch (CaException e) { log.error("Error retrieving the certificate"); } return null; }
From source file:org.medici.bia.dao.titleoccslist.TitleOccsListDAOJpaImpl.java
/** * {@inheritDoc}//from w w w . j a va 2 s . c om */ @SuppressWarnings("unchecked") @Override public Page searchTitlesOrOccupations(SimpleSearchTitleOrOccupation simpleSearchTitleOrOccupation, PaginationFilter paginationFilter) throws PersistenceException { // We prepare object of return method. Page page = new Page(paginationFilter); // select a.TitleOccID, a.TitleOcc, count(b.personId) from tblTitleOccsList a left outer join tblPoLink b on b.TitleOccID = a.TitleOccID group by a.titleOccID StringBuilder stringBuilder = new StringBuilder( "select a.titleOccID, a.titleOcc, count(b.personId) from tblTitleOccsList a"); stringBuilder.append(" left join tblPoLink b on b.titleOccID = a.TitleOccID "); if (simpleSearchTitleOrOccupation.getTextSearch() != null) { stringBuilder.append(" where a.titleOcc LIKE '%"); stringBuilder.append(simpleSearchTitleOrOccupation.getTextSearch()); stringBuilder.append("%' "); } else if (simpleSearchTitleOrOccupation.getRoleCatId() != null) { stringBuilder.append(" where a.roleCatMinorId="); stringBuilder.append(simpleSearchTitleOrOccupation.getRoleCatId()); } stringBuilder.append(" group by a.titleOccID "); // We set size of result. if (paginationFilter.getTotal() == null) { //select count(*) from ( select count(*) from tblTitleOccsList a left outer join tblPoLink b on b.TitleOccID = a.TitleOccID group by a.titleOccID ) count StringBuilder queryCountBuilder = new StringBuilder(""); queryCountBuilder.append("select count(*) from tblTitleOccsList a "); if (simpleSearchTitleOrOccupation.getTextSearch() != null) { queryCountBuilder.append(" where a.titleOcc LIKE '%"); queryCountBuilder.append(simpleSearchTitleOrOccupation.getTextSearch()); queryCountBuilder.append("%' "); } else if (simpleSearchTitleOrOccupation.getRoleCatId() != null) { queryCountBuilder.append(" where a.roleCatMinorID="); queryCountBuilder.append(simpleSearchTitleOrOccupation.getRoleCatId()); } // In this case we use Native Query!!! Query query = getEntityManager().createNativeQuery(queryCountBuilder.toString()); // Count(*) in native query is mapped as BigInteger, so we need to convert to Long... BigInteger result = (BigInteger) query.getSingleResult(); page.setTotal(NumberUtils.createLong(result.toString())); } // We invoke native query beacuse we use left outer join with on condition Query query = getEntityManager().createNativeQuery(stringBuilder.toString()); query.setFirstResult(paginationFilter.getFirstRecord()); query.setMaxResults(paginationFilter.getLength()); List<Object> list = (List<Object>) query.getResultList(); List<Object> result = new ArrayList<Object>(list.size()); for (int i = 0; i < list.size(); i++) { Object[] singleRow = (Object[]) list.get(i); List<Object> row = new ArrayList<Object>(0); row.add(new TitleOccsList((Integer) singleRow[0], (String) singleRow[1])); row.add(NumberUtils.createLong(((BigInteger) singleRow[2]).toString())); result.add(row); } // We set search result on return method page.setList(result); return page; }
From source file:nl.strohalm.cyclos.utils.conversion.CardNumberConverter.java
public String toString(final BigInteger number) { if (number == null) { return null; }/*from w w w . j av a2 s .c om*/ int numbers = 0; for (int i = 0; i < pattern.length(); i++) { final char c = pattern.charAt(i); if (ALLOWED_BOUNDARY_CHARS.indexOf(c) >= 0) { numbers++; } } final String data = StringUtils.leftPad(number.toString(), numbers, '0'); final StringBuffer formatedCardNumber = new StringBuffer(); int numberDigit = 0; for (int i = 0; i < pattern.length(); i++) { final char c = pattern.charAt(i); if (ALLOWED_BOUNDARY_CHARS.indexOf(c) >= 0) { formatedCardNumber.append(data.charAt(numberDigit)); numberDigit++; } else { formatedCardNumber.append(c); } } return formatedCardNumber.toString(); }
From source file:be.fedict.trust.service.bean.TrustServiceTrustLinker.java
public TrustLinkerResult hasTrustLink(X509Certificate childCertificate, X509Certificate certificate, Date validationDate, RevocationData revocationData) { LOG.debug("certificate: " + childCertificate.getSubjectX500Principal()); LOG.debug("certificate Issuer: " + childCertificate.getIssuerX500Principal().toString()); LOG.debug("Issuer: " + certificate.getSubjectX500Principal()); BigInteger issuerSerialNumber = certificate.getSerialNumber(); String key = new String(); key += certificate.getSubjectX500Principal().toString() + "|" + issuerSerialNumber.toString(); String issuerName = childCertificate.getIssuerX500Principal().toString(); CertificateAuthorityEntity certificateAuthority = this.entityManager //.find(CertificateAuthorityEntity.class, issuerName); .find(CertificateAuthorityEntity.class, key); if (null == certificateAuthority) { LOG.debug("no data cache entry for CA: " + issuerName + " - Serial Number: " + issuerSerialNumber.toString()); /*/* w w w. jav a 2s . c om*/ * Cache Miss */ SNMPInterceptor.increment(SnmpConstants.CACHE_MISSES, SnmpConstants.SNMP_SERVICE, 1L); /* * Lookup Root CA's trust point via parent certificates' CA entity. */ String parentIssuerName = certificate.getIssuerX500Principal().toString(); CertificateAuthorityEntity parentCertificateAuthority = this.entityManager .find(CertificateAuthorityEntity.class, parentIssuerName); if (null == parentCertificateAuthority) { logAudit("CA not found for " + parentIssuerName); LOG.error("CA not found for " + parentIssuerName + " ?!"); return null; } // create new CA try { certificateAuthority = new CertificateAuthorityEntity(getCrlUrl(childCertificate), certificate); certificateAuthority.setTrustPoint(parentCertificateAuthority.getTrustPoint()); } catch (CertificateEncodingException e) { LOG.error("certificate encoding error: " + e.getMessage(), e); return null; } this.entityManager.persist(certificateAuthority); return null; } if (Status.ACTIVE != certificateAuthority.getStatus()) { LOG.debug("CA revocation data cache not yet active: " + issuerName); /* * Harvester is still busy processing the first CRL. */ if (null == certificateAuthority.getCrlUrl()) { certificateAuthority.setCrlUrl(getCrlUrl(childCertificate)); } if (Status.NONE != certificateAuthority.getStatus()) { // none means no CRL is available so not really a cache miss SNMPInterceptor.increment(SnmpConstants.CACHE_MISSES, SnmpConstants.SNMP_SERVICE, 1L); } return null; } /* * Let's use the cached revocation data */ Date thisUpdate = certificateAuthority.getThisUpdate(); if (null == thisUpdate) { LOG.warn("no thisUpdate value: " + certificateAuthority.getName()); SNMPInterceptor.increment(SnmpConstants.CACHE_MISSES, SnmpConstants.SNMP_SERVICE, 1L); return null; } Date nextUpdate = certificateAuthority.getNextUpdate(); if (null == nextUpdate) { LOG.warn("no nextUpdate value: " + certificateAuthority.getName()); SNMPInterceptor.increment(SnmpConstants.CACHE_MISSES, SnmpConstants.SNMP_SERVICE, 1L); return null; } /* * First check whether the cached revocation data is up-to-date. */ if (thisUpdate.after(validationDate)) { LOG.warn("cached CRL data too recent: " + certificateAuthority.getName()); SNMPInterceptor.increment(SnmpConstants.CACHE_MISSES, SnmpConstants.SNMP_SERVICE, 1L); return null; } if (validationDate.after(nextUpdate)) { LOG.warn("cached CRL data too old: " + certificateAuthority.getName()); SNMPInterceptor.increment(SnmpConstants.CACHE_MISSES, SnmpConstants.SNMP_SERVICE, 1L); return null; } LOG.debug("using cached CRL data"); /* * Cache Hit */ SNMPInterceptor.increment(SnmpConstants.CACHE_HITS, SnmpConstants.SNMP_SERVICE, 1L); BigInteger serialNumber = childCertificate.getSerialNumber(); RevokedCertificateEntity revokedCertificate = findRevokedCertificate(issuerName, serialNumber); if (null == revokedCertificate) { LOG.debug("certificate valid: " + childCertificate.getSubjectX500Principal()); return new TrustLinkerResult(true); } if (revokedCertificate.getRevocationDate().after(validationDate)) { LOG.debug("CRL OK for: " + childCertificate.getSubjectX500Principal() + " at " + validationDate); return new TrustLinkerResult(true); } LOG.debug("certificate invalid: " + childCertificate.getSubjectX500Principal()); return new TrustLinkerResult(false, TrustLinkerResultReason.INVALID_REVOCATION_STATUS, "certificate revoked by cached CRL"); }
From source file:eu.dety.burp.joseph.attacks.bleichenbacher_pkcs1.gui.BleichenbacherPkcs1DecryptionAttackPanel.java
/** * Set the currently found s value on text widget * //from ww w .ja v a 2s. com * @param s * BigInteger s value */ public void setCurrentSValue(BigInteger s) { this.currentSValue.setText(s.toString()); }
From source file:be.fedict.trust.service.dao.bean.CertificateAuthorityDAOBean.java
public void updateRevokedCertificates(Set<X509CRLEntry> revokedCertificates, BigInteger crlNumber, X500Principal crlIssuer, Map<String, RevokedCertificateEntity> revokedCertificatesMap) { LOG.debug("Update " + revokedCertificates.size() + " revoked certificates (crlNumber=" + crlNumber + ")"); for (X509CRLEntry revokedCertificate : revokedCertificates) { X500Principal certificateIssuer = revokedCertificate.getCertificateIssuer(); String issuerName;// www. j a v a 2s . c o m if (null == certificateIssuer) { issuerName = crlIssuer.toString(); } else { issuerName = certificateIssuer.toString(); } BigInteger serialNumber = revokedCertificate.getSerialNumber(); Date revocationDate = revokedCertificate.getRevocationDate(); // lookup RevokedCertificateEntity revokedCertificateEntity = revokedCertificatesMap.get(serialNumber.toString()); if (null != revokedCertificateEntity) { // already exists, update revocationDate and crl number revokedCertificateEntity.setRevocationDate(revocationDate); revokedCertificateEntity.setCrlNumber(crlNumber); } else { // don't exist yet, add this.entityManager .persist(new RevokedCertificateEntity(issuerName, serialNumber, revocationDate, crlNumber)); } } }
From source file:com.sesnu.orion.web.service.ReportService.java
public String generateOrderAuthReport(Approval appr, String state) throws DocumentException, IOException { Bid bid = bidDao.get(appr.getForId()); OrderView order = orderDao.get(bid.getOrderRef()); Item item = itemDao.get(order.getItemId()); List<BidView> bids = bidDao.list(order.getId()); String orginalHtml = conf.getFile("orderAuth.html"); Estimate est = estService.totalEstimate(order, null, bid, item); String editedHtml = orginalHtml.replace("ORDER_DATE", Util.parseDate(order.getCreatedOn())); editedHtml = setPaths(editedHtml, state); editedHtml = editedHtml.replace("PRODUCT_NAME", item.getName()); editedHtml = editedHtml.replace("ORDERED_BY", order.getOrderedBy()); editedHtml = editedHtml.replace("BRAND_NAME", item.getBrand()); editedHtml = editedHtml.replace("DEPARTMENT", "Import"); // whose department ? editedHtml = editedHtml.replace("PACKAGING", order.getBaseSize().toString() + order.getBaseUnit() + "X" + order.getQtyPerPack() + "pcs"); editedHtml = editedHtml.replace("BUDGET_REF", order.getBudgetRef()); editedHtml = editedHtml.replace("QTY_PER_CONT", order.getPckPerCont().toString()); editedHtml = editedHtml.replace("DESTINATION", order.getDestinationPort()); editedHtml = editedHtml.replace("QUANTITY", order.getContQnt() + "X" + order.getContSize() + "'"); editedHtml = editedHtml.replace("LATEST_ETA", Util.parseDate(order.getLatestETA())); editedHtml = editedHtml.replace("IN_TRANSIT", shipDao.InTransitCount(item.getId()).toString()); editedHtml = editedHtml.replace("IN_PORT", shipDao.InPortCount(item.getId()).toString()); editedHtml = editedHtml.replace("IN_TERMINAL", shipDao.InTerminalCount(item.getId()).toString()); BigInteger newItemOrders = orderDao.newOrdersCount(item.getId()).subtract(new BigInteger("1")); editedHtml = editedHtml.replace("NEW_ORDERS", newItemOrders.toString()); editedHtml = editedHtml.replace("ORDER_DATE", bid.getUpdatedOn()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bids.size(); i++) { BidView abid = bids.get(i);// www. j av a 2s. c o m sb.append("<tr>"); sb.append("<td>"); sb.append(i + 1); sb.append("</td>"); sb.append("<td>"); sb.append(abid.getSupplier()); sb.append("</td>"); sb.append("<td>"); sb.append(abid.getCifCnf()); sb.append("</td>"); sb.append("<td>"); sb.append(abid.getFob()); sb.append("</td>"); sb.append("<td>"); sb.append(abid.getCurrency()); sb.append("</td>"); sb.append("<td>"); sb.append(abid.getPaymentMethod() == null ? "" : abid.getPaymentMethod()); sb.append("</td>"); sb.append("<td>"); sb.append(abid.isSelected() ? "Yes" : "No"); sb.append("</td>"); sb.append("<td>"); sb.append(abid.getRemark() == null ? "" : abid.getRemark()); sb.append("</td>"); sb.append("</tr>"); } editedHtml = editedHtml.replace("BID_DATA_TABLE", sb.toString()); editedHtml = editedHtml.replace("EST_TRANSIT_DAYS", bid.getEstTransitDays().toString()); Calendar c = Calendar.getInstance(); c.setTime(order.getLatestETA()); c.add(Calendar.DATE, bid.getEstTransitDays()); editedHtml = editedHtml.replace("LATEST_DATE_OF_SHIP", Util.parseDate(c.getTime())); editedHtml = editedHtml.replace("IMPORTER", order.getImporter()); Exchange cur = exchangeDao.get("Other", "Other", "USD", "AOA"); if (cur == null) { return null; } editedHtml = editedHtml.replace("TOTAL_CNF_USD", Util.parseCurrency(bid.getTotalBid())); Double pricePerPack = (bid.getTotalBid() * cur.getRate() + est.getValue()) / order.getContQnt() / order.getPckPerCont(); pricePerPack = pricePerPack / cur.getRate(); pricePerPack = (double) (Math.round(pricePerPack * 100.0) / 100); editedHtml = editedHtml.replace("LANDED_COST_TO_WH", pricePerPack.toString()); Double totalEstPrice = pricePerPack * 1.12; editedHtml = editedHtml.replace("COST_PLUS_MRG", totalEstPrice.toString()); String emailTo = appr.getRequestedBy() + " [" + (userDao.getUserName(appr.getRequestedBy())).getEmail() + "]"; String emailCC = appr.getApprover() + " [" + (userDao.getUserName(appr.getApprover())).getEmail() + "]"; editedHtml = editedHtml.replace("EMAIL_TO", emailTo); editedHtml = editedHtml.replace("EMAIL_CC", emailCC); if (!state.equals("preview")) { editedHtml = editedHtml.replace("SIGNATURE", appr.getApprover()); editedHtml = editedHtml.replace("APPROVED_ON", new Date().toGMTString()); String pdfFilePath = util.convertToPdf(editedHtml); // convert to pdf Path path = Paths.get(pdfFilePath); byte[] data = Files.readAllBytes(path); // convert to byte array String[] frag = pdfFilePath.split("/"); String fileName = frag[frag.length - 1]; // get file name util.writeToS3(data, fileName); // write to s3 sendApprovalEmail(appr, pdfFilePath, order); Files.deleteIfExists(path); Document doc = new Document(order.getId(), fileName, "Order Authorization", Util.parseDate(new Date()), ""); docDao.saveOrUpdate(doc); } else { editedHtml = editedHtml.replace("APPROVED_ON", ""); } return editedHtml; }
From source file:org.ossie.properties.AnyUtils.java
/** * Attempts to convert the string value to the appropriate Java type. * /*from ww w .j a v a2 s. c o m*/ * @param stringValue the string form of the value * @param type the string form of the TypeCode * @return A Java object of theString corresponding to the typecode */ public static Object convertString(final String stringValue, final String type) { if (stringValue == null) { return null; } if (type.equals("string")) { return stringValue; } else if (type.equals("wstring")) { return stringValue; } else if (type.equals("boolean")) { if ("true".equalsIgnoreCase(stringValue) || "false".equalsIgnoreCase(stringValue)) { return Boolean.parseBoolean(stringValue); } throw new IllegalArgumentException(stringValue + " is not a valid boolean value"); } else if (type.equals("char")) { if (stringValue.length() == 1) { return stringValue.charAt(0); } throw new IllegalArgumentException(stringValue + " is not a valid char value"); } else if (type.equals("wchar")) { return stringValue.charAt(0); } else if (type.equals("double")) { return Double.parseDouble(stringValue); } else if (type.equals("float")) { return Float.parseFloat(stringValue); } else if (type.equals("short")) { return Short.decode(stringValue); } else if (type.equals("long")) { return Integer.decode(stringValue); } else if (type.equals("longlong")) { return Long.decode(stringValue); } else if (type.equals("ulong")) { final long MAX_UINT = 2L * Integer.MAX_VALUE + 1L; final Long retVal = Long.decode(stringValue); if (retVal < 0 || retVal > MAX_UINT) { throw new IllegalArgumentException( "ulong value must be greater than '0' and less than " + MAX_UINT); } return retVal; } else if (type.equals("ushort")) { final int MAX_USHORT = 2 * Short.MAX_VALUE + 1; final Integer retVal = Integer.decode(stringValue); if (retVal < 0 || retVal > MAX_USHORT) { throw new IllegalArgumentException( "ushort value must be greater than '0' and less than " + MAX_USHORT); } return retVal; } else if (type.equals("ulonglong")) { final BigInteger MAX_ULONG_LONG = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)) .add(BigInteger.ONE); final BigInteger retVal = bigIntegerDecode(stringValue); if (retVal.compareTo(BigInteger.ZERO) < 0 || retVal.compareTo(MAX_ULONG_LONG) > 0) { throw new IllegalArgumentException( "ulonglong value must be greater than '0' and less than " + MAX_ULONG_LONG.toString()); } return retVal; } else if (type.equals("objref")) { List<String> objrefPrefix = Arrays.asList("IOR:", "corbaname:", "corbaloc:"); for (String prefix : objrefPrefix) { if (stringValue.startsWith(prefix)) { return stringValue; } } throw new IllegalArgumentException(stringValue + " is not a valid objref value"); } else if (type.equals("octet")) { final short MIN_OCTET = 0; final short MAX_OCTET = 0xFF; short val = Short.valueOf(stringValue); if (val <= MAX_OCTET && val >= MIN_OCTET) { return Short.valueOf(val).byteValue(); } throw new IllegalArgumentException(stringValue + " is not a valid octet value"); } else { throw new IllegalArgumentException("Unknown CORBA Type: " + type); } }
From source file:org.smartfrog.services.deployapi.engine.ServerInstance.java
@SuppressWarnings("deprecation") private Element makeStaticStatus() { Element status = Xom5Utils.element(Constants.PROPERTY_PORTAL_STATIC_PORTAL_STATUS); Element portal = XomHelper.apiElement(StatusElements.PORTAL); status.appendChild(portal);// w ww .j av a 2 s. c om portal.appendChild(XomHelper.apiElement(StatusElements.NAME, Constants.BUILD_INFO_IMPLEMENTATION_NAME)); portal.appendChild(XomHelper.apiElement(StatusElements.BUILD, BUILD_TIMESTAMP)); portal.appendChild(XomHelper.apiElement(StatusElements.LOCATION, location)); portal.appendChild(XomHelper.apiElement(StatusElements.HOME, Constants.BUILD_INFO_HOMEPAGE)); Date now = new Date(); BigInteger tzoffset = BigInteger.valueOf(now.getTimezoneOffset()); portal.appendChild(XomHelper.apiElement(StatusElements.TIMEZONE_UTCOFFSET, tzoffset.toString())); Element languages = XomHelper.apiElement(StatusElements.LANGUAGES); Element cdl = XomHelper.apiElement(StatusElements.ITEM); Element name = XomHelper.apiElement(StatusElements.NAME, Constants.BUILD_INFO_CDL_LANGUAGE); Element uri = XomHelper.apiElement(StatusElements.URI, Constants.XML_CDL_NAMESPACE); cdl.appendChild(name); cdl.appendChild(uri); languages.appendChild(cdl); status.appendChild(languages); Element sfrog = XomHelper.apiElement(StatusElements.ITEM); name = XomHelper.apiElement(StatusElements.NAME, Constants.BUILD_INFO_SF_LANGUAGE); uri = XomHelper.apiElement(StatusElements.URI, Constants.SMARTFROG_NAMESPACE); sfrog.appendChild(name); sfrog.appendChild(uri); languages.appendChild(sfrog); Element notifications = XomHelper.apiElement(StatusElements.NOTIFICATIONS); Element wsrf = XomHelper.apiElement(StatusElements.ITEM, Constants.WSRF_WSNT_NAMESPACE); notifications.appendChild(wsrf); status.appendChild(notifications); Element options = XomHelper.apiElement(StatusElements.OPTIONS); status.appendChild(options); return status; }