Example usage for java.math BigInteger TEN

List of usage examples for java.math BigInteger TEN

Introduction

In this page you can find the example usage for java.math BigInteger TEN.

Prototype

BigInteger TEN

To view the source code for java.math BigInteger TEN.

Click Source Link

Document

The BigInteger constant ten.

Usage

From source file:org.sinekartads.integration.pdf.SignPDFonAlfresco.java

@Test
public void test() throws Exception {
    if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
        Security.addProvider(new BouncyCastleProvider());
    }/* w  ww  . j a  v  a  2s  . c o  m*/

    SignNOApplet applet = new SignNOApplet();
    try {

        // Main options
        boolean applyMark = false;
        boolean useFakeSmartCard = false;
        String driver;
        String scPin;
        if (useFakeSmartCard) {
            driver = "fake";
            scPin = "123";
        } else {
            driver = "libbit4ipki.so";
            scPin = "18071971";
        }

        // Test products
        String[] aliases;
        String alias;
        X509Certificate certificate;
        X509Certificate[] certificateChain;
        byte[] fingerPrint;
        byte[] digitalSignature;

        // Communication unities
        DocumentDTO[] documents;
        String jsonResp;
        SkdsDocumentDetailsResponse detailsResp;
        SkdsPreSignResponse preSignResp;
        SkdsPostSignResponse postSignResp;
        AppletResponseDTO appletResponse;
        SignatureDTO emptySignatureDTO;
        SignatureDTO chainSignatureDTO;
        SignatureDTO digestSignatureDTO;
        SignatureDTO signedSignatureDTO;
        SignatureDTO finalizedSignatureDTO;
        VerifyDTO verifyDTO;

        // Init the applet
        try {
            AppletRequestDTO req = new AppletRequestDTO();
            req.setDriver(driver);
            appletResponse = applet.selectDriver(req);
        } catch (Exception e) {
            tracer.error("error during the applet initialization", e);
            throw e;
        }

        // Login with the smartCard
        try {
            AppletRequestDTO req = new AppletRequestDTO();
            req.setDriver(driver);
            req.setPin(scPin);
            appletResponse = applet.login(req);
            aliases = (String[]) JSONUtils.deserializeJSON(String[].class, extractJSON(appletResponse));
        } catch (Exception e) {
            tracer.error("error during the applet login", e);
            throw e;
        }

        // Choose the signing alias
        StringBuilder buf = new StringBuilder();
        for (String a : aliases) {
            buf.append(a).append(" ");
        }
        alias = aliases[0];
        tracer.info(String.format("available aliases:   %s", buf));
        tracer.info(String.format("signing alias:       %s", alias));

        // Load the certificate chain from the applet
        try {
            AppletRequestDTO req = new AppletRequestDTO();
            req.setDriver(driver);
            req.setPin(scPin);
            req.setAlias(alias);
            appletResponse = applet.selectCertificate(req);
            certificate = (X509Certificate) X509Utils.rawX509CertificateFromHex(extractJSON(appletResponse));
            tracer.info(String.format("certificate:         %s", certificate));
            certificateChain = new X509Certificate[] { certificate };
        } catch (Exception e) {
            tracer.error("error during the certificate selection", e);
            throw e;
        }

        // FindRefByName
        String sourceRef = null;
        try {
            SkdsFindRefByNameRequest req = new SkdsFindRefByNameRequest();
            req.setName(SOURCE_NAME);
            SkdsFindRefByNameResponse findResp = postJsonRequest(req, SkdsFindRefByNameResponse.class);
            if (ResultCode.valueOf(findResp.getResultCode()) == ResultCode.SUCCESS) {
                sourceRef = findResp.getNodeRef();
            } else {
                throw new Exception(findResp.getMessage());
            }
        } catch (Exception e) {
            tracer.error("error during the pre sign phase", e);
            throw e;
        }

        // DocumentDetails
        try {
            SkdsDocumentDetailsRequest req = new SkdsDocumentDetailsRequest();
            req.setNodeRefs(new String[] { sourceRef });
            detailsResp = postJsonRequest(req, SkdsDocumentDetailsResponse.class);
            if (ResultCode.valueOf(detailsResp.getResultCode()) == ResultCode.SUCCESS) {
                documents = detailsResp.documentsFromBase64();
            } else {
                throw new Exception(detailsResp.getMessage());
            }
            Assert.isTrue(StringUtils.equals(documents[0].getBaseDocument().getMimetype(), "application/pdf"));
            String baseName = FilenameUtils.getBaseName(documents[0].getBaseDocument().getFileName());
            if (applyMark) {
                documents[0].setDestName(baseName + "_mrk.pdf");
            } else {
                documents[0].setDestName(baseName + "_sgn.pdf");
            }
        } catch (Exception e) {
            tracer.error("error during the pre sign phase", e);
            throw e;
        }

        // empty signature - initialized with the SHA256withRSA and RSA algorithms
        emptySignatureDTO = new SignatureDTO();
        emptySignatureDTO.setSignAlgorithm(conf.getSignatureAlgorithm().getName());
        emptySignatureDTO.setDigestAlgorithm(conf.getDigestAlgorithm().getName());
        emptySignatureDTO.signCategoryToString(SignCategory.PDF);
        emptySignatureDTO.setPdfSignName("Signature");
        emptySignatureDTO.setPdfRevision("1");
        emptySignatureDTO.pdfCoversWholeDocumentToString(true);

        // Add to the empty signature the timeStamp request if needed
        TimeStampRequestDTO tsRequestDTO = new TimeStampRequestDTO();
        if (applyMark) {
            tsRequestDTO.timestampDispositionToString(SignDisposition.TimeStamp.ENVELOPING);
            tsRequestDTO.messageImprintAlgorithmToString(DigestAlgorithm.SHA256);
            tsRequestDTO.nounceToString(BigInteger.TEN);
            tsRequestDTO.setTsUrl("http://ca.signfiles.com/TSAServer.aspx");
        }
        emptySignatureDTO.setTimeStampRequest(tsRequestDTO);

        // chain signature - contains the certificate chain
        chainSignatureDTO = TemplateUtils.Instantiation.clone(emptySignatureDTO);
        chainSignatureDTO.certificateChainToHex(certificateChain);
        documents[0].setSignatures(new SignatureDTO[] { chainSignatureDTO });

        // PreSign phase - join the content with the certificate chain and evaluate the digest
        try {
            SkdsPreSignRequest req = new SkdsPreSignRequest();
            req.documentsToBase64(documents);
            preSignResp = postJsonRequest(req, SkdsPreSignResponse.class);
            if (ResultCode.valueOf(preSignResp.getResultCode()) == ResultCode.SUCCESS) {
                documents = preSignResp.documentsFromBase64();
                digestSignatureDTO = documents[0].getSignatures()[0];
            } else {
                throw new Exception(preSignResp.getMessage());
            }
        } catch (Exception e) {
            tracer.error("error during the pre sign phase", e);
            throw e;
        }

        // signed signature - sign the digest with the smartCard to obtain the digitalSignature
        try {
            fingerPrint = digestSignatureDTO.getDigest().fingerPrintFromHex();
            tracer.info(String.format("fingerPrint:         %s", HexUtils.encodeHex(fingerPrint)));
            AppletRequestDTO req = new AppletRequestDTO();
            req.setDriver(driver);
            req.setPin(scPin);
            req.setAlias(alias);
            req.setHexDigest(HexUtils.encodeHex(fingerPrint));
            appletResponse = applet.signDigest(req);
            digitalSignature = HexUtils.decodeHex((String) extractJSON(appletResponse));
            tracer.info(String.format("digitalSignature:    %s", HexUtils.encodeHex(digitalSignature)));
            signedSignatureDTO = TemplateUtils.Instantiation.clone(digestSignatureDTO);
            signedSignatureDTO.digitalSignatureToHex(digitalSignature);
            documents[0].getSignatures()[0] = signedSignatureDTO;
        } catch (Exception e) {
            tracer.error("error during the digital signature evaluation", e);
            throw e;
        }

        // PostSign phase - add the digitalSignature to the envelope and store the result into the JCLResultDTO
        try {
            SkdsPostSignRequest req = new SkdsPostSignRequest();
            req.documentsToBase64(documents);
            postSignResp = postJsonRequest(req, SkdsPostSignResponse.class);
            if (ResultCode.valueOf(postSignResp.getResultCode()) == ResultCode.SUCCESS) {
                documents = postSignResp.documentsFromBase64();
                finalizedSignatureDTO = documents[0].getSignatures()[0];
            } else {
                throw new Exception(postSignResp.getMessage());
            }
        } catch (Exception e) {
            tracer.error("error during the envelope generation", e);
            throw e;
        }

        //         // Verify phase - load the envelope content and verify the nested signature 
        //         try {
        //            jsonResp = signatureService.verify ( envelopeHex, null, null, VerifyResult.VALID.name() );
        //            verifyDTO = extractResult ( VerifyDTO.class, jsonResp );
        //         } catch(Exception e) {
        //            tracer.error("error during the envelope verification", e);
        //            throw e;
        //         }
        //         
        //         // finalized signature - enveloped signed and eventually marked, not modifiable anymore
        //         try {
        //            verifyResult = (VerifyInfo) converter.toVerifyInfo( verifyDTO );
        //         } catch(Exception e) {
        //            tracer.error("unable to obtain the verifyInfo from the DTO", e);
        //            throw e;
        //         }
        //         
        //         try {
        //            for(VerifiedSignature < ?, ?, VerifyResult, ?> verifiedSignature : verifyResult.getSignatures() ) {
        //               tracer.info(String.format ( "signature validity:  %s", verifiedSignature.getVerifyResult().name() ));
        //               tracer.info(String.format ( "signature type:      %s", verifiedSignature.getSignType().name() ));
        //               tracer.info(String.format ( "disposition:         %s", verifiedSignature.getDisposition().name() ));
        //               tracer.info(String.format ( "digest algorithm:    %s", verifiedSignature.getDigest().getAlgorithm().name() ));
        //               tracer.info(String.format ( "finger print:        %s", HexUtils.encodeHex(verifiedSignature.getDigest().getFingerPrint()) ));
        //               tracer.info(String.format ( "counter signature:   %s", verifiedSignature.isCounterSignature() ));
        //               tracer.info(String.format ( "signature algorithm: %s", verifiedSignature.getSignAlgorithm().name() ));
        //               tracer.info(String.format ( "digital signature:   %s", HexUtils.encodeHex(verifiedSignature.getDigitalSignature()) ));
        //               tracer.info(String.format ( "reason:              %s", verifiedSignature.getReason() ));
        //               tracer.info(String.format ( "signing location:    %s", verifiedSignature.getLocation() ));
        //               tracer.info(String.format ( "signing time:        %s", formatDate(verifiedSignature.getSigningTime()) ));
        //               tracer.info(String.format ( "\n "));
        //               tracer.info(String.format ( "signing certificate chain: "));
        //               for ( X509Certificate cert : verifiedSignature.getRawX509Certificates() ) {
        //                  showCertificate(cert);
        //               }
        //               if ( verifiedSignature.getTimeStamps() != null ) {
        //                  tracer.info(String.format ( "\n "));
        //                  tracer.info(String.format ( "timestamps: "));
        //                  for ( TimeStampInfo mark : verifiedSignature.getTimeStamps() ) {
        //                     tracer.info(String.format ( "timestamp validity:  %s", mark.getVerifyResult().name() ));
        //                     tracer.info(String.format ( "timestamp authority: %s", mark.getTsaName() ));
        //                     tracer.info(String.format ( "timestamp authority: %s", mark.getTsaName() ));
        //                     tracer.info(String.format ( "message imprint alg: %s", mark.getMessageInprintInfo().getAlgorithm().name() ));
        //                     tracer.info(String.format ( "message imprint:     %s", HexUtils.encodeHex(mark.getMessageInprintInfo().getFingerPrint()) ));
        //                     tracer.info(String.format ( "digest algorithm:    %s", mark.getDigestAlgorithm().name() ));
        //                     tracer.info(String.format ( "digital signature:   %s", HexUtils.encodeHex(mark.getDigitalSignature()) ));
        //                     tracer.info(String.format ( "signature algorithm: %s", mark.getSignAlgorithm().name() ));
        //                     tracer.info(String.format ( "timestamp certificate: "));
        //                     for ( X509Certificate cert : mark.getRawX509Certificates() ) {
        //                        showCertificate(cert);
        //                     }
        //                  }
        //               }
        //            }
        //         } catch(Exception e) {
        //            tracer.error("unable to print the verify results", e);
        //            throw e;
        //         }

    } finally {
        applet.close();
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

@SuppressWarnings("unchecked")
@Test/*  ww  w .j a v a  2  s  .  c om*/
public void testPostGetRecordsDistributedSearchSetToTen()
        throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    DistributedSearchType distributedSearch = new DistributedSearchType();
    distributedSearch.setHopCount(BigInteger.TEN);

    grr.setDistributedSearch(distributedSearch);

    QueryRequest queryRequest = queryFactory.getQuery(grr);
    assertThat(queryRequest.isEnterprise(), is(true));
    assertThat(queryRequest.getSourceIds(), anyOf(nullValue(), empty()));
}

From source file:com.workday.autoparse.xml.demo.XmlParserTest.java

@Test
public void testMissingAttributesAreNotSet()
        throws ParseException, UnexpectedChildException, UnknownElementException {
    XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser();
    InputStream in = getInputStreamOf("missing-attributes.xml");

    DemoModel model = (DemoModel) parser.parseStream(in);

    assertTrue(model.myBoxedBoolean);/*from  w ww  .j  a  v  a 2 s .  c  o m*/
    assertTrue(model.myPrimitiveBoolean);
    assertEquals(BigDecimal.ONE, model.myBigDecimal);
    assertEquals(BigInteger.TEN, model.myBigInteger);
    assertEquals(-1, model.myPrimitiveByte);
    assertEquals(Byte.valueOf((byte) -1), model.myBoxedByte);
    assertEquals('a', model.myPrimitiveChar);
    assertEquals(Character.valueOf('a'), model.myBoxedChar);
    assertEquals(-1.0, model.myPrimitiveDouble, DOUBLE_E);
    assertEquals(Double.valueOf(-1.0), model.myBoxedDouble);
    assertEquals(-1f, model.myPrimitiveFloat, FLOAT_E);
    assertEquals(Float.valueOf(-1f), model.myBoxedFloat);
    assertEquals(-1, model.myPrimitiveInt);
    assertEquals(Integer.valueOf(-1), model.myBoxedInt);
    assertEquals(-1, model.myPrimitiveLong);
    assertEquals(Long.valueOf(-1), model.myBoxedLong);
    assertEquals(-1, model.myPrimitiveShort);
    assertEquals(Short.valueOf((short) -1), model.myBoxedShort);
    assertEquals("default", model.myString);
    assertEquals("default", model.myTextContent);
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

@SuppressWarnings("unchecked")
@Test//  w  w w  . j  av a2s  .  c om
public void testPostGetRecordsDistributedSearchSpecificSources()
        throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    DistributedSearchType distributedSearch = new DistributedSearchType();
    distributedSearch.setHopCount(BigInteger.TEN);

    grr.setDistributedSearch(distributedSearch);

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<QName>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));

    query.setTypeNames(typeNames);
    QueryConstraintType constraint = new QueryConstraintType();

    constraint.setCqlText(CQL_FEDERATED_QUERY);

    query.setConstraint(constraint);

    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);

    QueryRequest queryRequest = queryFactory.getQuery(grr);
    assertThat(queryRequest.isEnterprise(), is(false));
    assertThat(queryRequest.getSourceIds(), contains("source1"));
}

From source file:net.ripe.rpki.validator.commands.TopDownWalkerTest.java

private X509Crl getCrl() {
    X509CrlBuilder builder = new X509CrlBuilder();
    builder.withIssuerDN(new X500Principal("CN=issuer"));
    builder.withThisUpdateTime(new DateTime());
    builder.withNextUpdateTime(new DateTime().plusHours(8));
    builder.withNumber(BigInteger.TEN);
    builder.withAuthorityKeyIdentifier(ROOT_KEY_PAIR.getPublic());
    return builder.build(ROOT_KEY_PAIR.getPrivate());
}

From source file:co.rsk.peg.BridgeStorageProviderTest.java

private BtcTransaction createTransaction() {
    BtcTransaction tx = new BtcTransaction(networkParameters);
    tx.addInput(PegTestUtils.createHash(), transactionOffset++,
            ScriptBuilder.createInputScript(new TransactionSignature(BigInteger.ONE, BigInteger.TEN)));

    return tx;//from  w ww  .  ja  v  a 2 s  .c om
}

From source file:org.qi4j.runtime.value.CollectionTypeTest.java

private Collection<BigInteger> bigIntegerCollection() {
    Collection<BigInteger> value = new ArrayList<BigInteger>();
    value.add(new BigInteger("-1"));
    value.add(BigInteger.ZERO);/*ww w.  j  a  va  2s .co m*/
    value.add(BigInteger.ONE);
    value.add(null);
    value.add(BigInteger.TEN);
    value.add(new BigInteger("-1827368263823729372397239829332"));
    value.add(new BigInteger("2398723982982379827373972398723"));
    return value;
}

From source file:io.instacount.client.InstacountClientTest.java

@Test
public void testIncrement_Sync() throws InstacountClientException {
    final String counterName = UUID.randomUUID().toString();
    final IncrementShardedCounterResponse response = client.incrementShardedCounter(counterName,
            new IncrementShardedCounterInput(BigInteger.TEN, SYNC));
    assertThat(response.getOptCounterOperation().isPresent(), is(true));
    assertThat(response.getOptCounterOperation().get().getAmount(), is(BigInteger.TEN));
    assertThat(response.getOptCounterOperation().get().getCounterOperationType(),
            is(CounterOperationType.INCREMENT));
    assertThat(response.getOptCounterOperation().get().getShardIndex(), anyOf(is(0), is(1), is(2)));
    assertThat(response.getOptCounterOperation().get().getId(), is(not(nullValue())));

    // Get the counter and assert its value!
    assertThat(client.getShardedCounter(counterName).getShardedCounter().getCount(), is(BigInteger.TEN));
}

From source file:io.instacount.client.InstacountClientTest.java

@Test
public void testIncrement_Async() throws InstacountClientException {
    final String counterName = UUID.randomUUID().toString();
    final IncrementShardedCounterResponse response = client.incrementShardedCounter(counterName,
            new IncrementShardedCounterInput(BigInteger.TEN, ASYNC));

    assertThat(response.getHttpResponseCode(), is(202));
    assertThat(response.getOptCounterOperation().isPresent(), is(false));

    // Get the counter and assert its value!
    assertThat(client.getShardedCounter(counterName).getHttpResponseCode(), anyOf(is(200), is(404)));
}

From source file:io.instacount.client.InstacountClientTest.java

@Test
public void testDecrement_Sync() throws InstacountClientException {
    final String counterName = UUID.randomUUID().toString();
    final DecrementShardedCounterResponse response = client.decrementShardedCounter(counterName,
            new DecrementShardedCounterInput(BigInteger.TEN, SYNC));
    assertThat(response.getOptCounterOperation().isPresent(), is(true));
    assertThat(response.getOptCounterOperation().get().getAmount(), is(BigInteger.TEN));
    assertThat(response.getOptCounterOperation().get().getCounterOperationType(),
            is(CounterOperationType.DECREMENT));
    assertThat(response.getOptCounterOperation().get().getShardIndex(), anyOf(is(0), is(1), is(2)));
    assertThat(response.getOptCounterOperation().get().getId(), is(not(nullValue())));

    // Get the counter and assert its value!
    assertThat(client.getShardedCounter(counterName).getShardedCounter().getCount(),
            is(BigInteger.valueOf(-10L)));
}