Example usage for org.bouncycastle.asn1 ASN1Integer ASN1Integer

List of usage examples for org.bouncycastle.asn1 ASN1Integer ASN1Integer

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 ASN1Integer ASN1Integer.

Prototype

public ASN1Integer(byte[] bytes) 

Source Link

Document

Construct an INTEGER from the passed in byte array.

Usage

From source file:tr.gov.turkiye.esign.cms.SignedData.java

/**
 * version is the syntax version number.  The appropriate value
   depends on certificates, eContentType, and SignerInfo
 * @return ASN1Integer instance/*  w w  w. j  av  a2 s .c om*/
 */
private ASN1Integer getCMSVersion() {
    ASN1Integer cmsVersion;
    if ((certs != null && certs.size() > 0) && anyCertificatesWithTypeOfOtherPresent()) {
        cmsVersion = new ASN1Integer(5);
    } else {
        if ((certs != null && certs.size() > 0) && anyVersionAttributeCertificatesPresent(2)) {
            cmsVersion = new ASN1Integer(4);
        } else if ((certs != null && certs.size() > 0) && (anyVersionAttributeCertificatesPresent(1))
                || (checkSignerInfoVersion(3))) {
            cmsVersion = new ASN1Integer(3);
        } else {
            cmsVersion = new ASN1Integer(1);
        }
    }
    return cmsVersion;
}

From source file:tr.gov.turkiye.esign.cms.SignerInfo.java

/**
 * Since the SignerIdentifier is the issuerAndSerialNumber, the version MUST be 1.
 * @return ASN1Integer instance/*from   w ww  .  j a v a2 s  . co  m*/
 */
public ASN1Integer getSignerVersion() {
    return new ASN1Integer(1);
}

From source file:tr.gov.turkiye.esign.cms.SignerInfo.java

/**
 * Gets signer's certificate's serial/*from ww w  . j a  v a  2 s. c  om*/
 * @return ASN1Integer isntance
 */
private ASN1Encodable getCertificateSerial() {
    return new ASN1Integer(cert.getSerialNumber());
}

From source file:tr.gov.turkiye.esign.cms.SigningCertificate.java

/**
 * Gets issuer and serial part from signing certificate
 * @param cert signing certificate/*from   w  w w  . j  a  v a 2s. c  om*/
 * @return DERSequence instance
 * @throws SmartCardException 
 */
private ASN1Encodable getIssuerAndSerialForESSCertId(Certificate cert) throws SmartCardException {
    try {
        final ASN1EncodableVector issuerSerialPart = new ASN1EncodableVector();
        issuerSerialPart.add(new DERSequence(new DERTaggedObject(true, 4, getIssuer(cert))));
        issuerSerialPart.add(new ASN1Integer(((X509Certificate) cert).getSerialNumber()));
        final DERSequence issuerSerial = new DERSequence(issuerSerialPart);
        return issuerSerial;
    } catch (CertificateEncodingException ex) {
        throw new SmartCardException(ExceptionSupport.getValue("CertificateEncodingException"), ex);
    } catch (IOException ex) {
        throw new SmartCardException(ExceptionSupport.getValue("IOException"), ex);
    }
}

From source file:us.eharning.atomun.core.ec.internal.BouncyCastleECKeyPair.java

License:Apache License

/**
 * Perform an ECDSA signature using the private key.
 *
 * @param hash//from www .j av a2  s  .c  o m
 *         byte array to sign.
 *
 * @return ASN.1 representation of the signature.
 */
@Nonnull
@Override
public byte[] sign(@Nonnull byte[] hash) {
    /* The HMacDSAKCalculator is what makes this signer RFC 6979 compliant. */
    ECDSASigner signer = new ECDSASigner(new RFC6979KCalculator(new SHA256Digest()));
    signer.init(true, new ECPrivateKeyParameters(privateExponent, domain));
    BigInteger[] signature = signer.generateSignature(hash);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    /* Need to canonicalize signature up front ... */
    if (CANONICALIZE && signature[1].compareTo(HALF_CURVE_ORDER) > 0) {
        /* BOP does not do this */
        signature[1] = curve.getN().subtract(signature[1]);
    }
    try {
        DERSequenceGenerator seq = new DERSequenceGenerator(stream);
        seq.addObject(new ASN1Integer(signature[0]));
        seq.addObject(new ASN1Integer(signature[1]));
        seq.close();
        return stream.toByteArray();
    } catch (IOException e) {
        throw new IllegalStateException("IOException should not be thrown", e);
    }
}