Search in sources :

Example 41 with DEROctetString

use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.

the class XMSSPrivateKey method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    if (maxIndex >= 0) {
        // version 1
        v.add(new ASN1Integer(1));
    } else {
        // version 0
        v.add(new ASN1Integer(0));
    }
    ASN1EncodableVector vK = new ASN1EncodableVector();
    vK.add(new ASN1Integer(index));
    vK.add(new DEROctetString(secretKeySeed));
    vK.add(new DEROctetString(secretKeyPRF));
    vK.add(new DEROctetString(publicSeed));
    vK.add(new DEROctetString(root));
    if (maxIndex >= 0) {
        vK.add(new DERTaggedObject(false, 0, new ASN1Integer(maxIndex)));
    }
    v.add(new DERSequence(vK));
    v.add(new DERTaggedObject(true, 0, new DEROctetString(bdsState)));
    return new DERSequence(v);
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) DERTaggedObject(com.github.zhenwei.core.asn1.DERTaggedObject) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString)

Example 42 with DEROctetString

use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.

the class McElieceCCA2PublicKey method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    // encode <n>
    v.add(new ASN1Integer(n));
    // encode <t>
    v.add(new ASN1Integer(t));
    // encode <matrixG>
    v.add(new DEROctetString(g.getEncoded()));
    v.add(digest);
    return new DERSequence(v);
}
Also used : DERSequence(com.github.zhenwei.core.asn1.DERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString)

Example 43 with DEROctetString

use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.

the class OCSPRespBuilder method build.

public OCSPResp build(int status, Object response) throws OCSPException {
    if (response == null) {
        return new OCSPResp(new OCSPResponse(new OCSPResponseStatus(status), null));
    }
    if (response instanceof BasicOCSPResp) {
        BasicOCSPResp r = (BasicOCSPResp) response;
        ASN1OctetString octs;
        try {
            octs = new DEROctetString(r.getEncoded());
        } catch (IOException e) {
            throw new OCSPException("can't encode object.", e);
        }
        ResponseBytes rb = new ResponseBytes(OCSPObjectIdentifiers.id_pkix_ocsp_basic, octs);
        return new OCSPResp(new OCSPResponse(new OCSPResponseStatus(status), rb));
    }
    throw new OCSPException("unknown response object");
}
Also used : ASN1OctetString(com.github.zhenwei.core.asn1.ASN1OctetString) ResponseBytes(com.github.zhenwei.core.asn1.ocsp.ResponseBytes) OCSPResponse(com.github.zhenwei.core.asn1.ocsp.OCSPResponse) OCSPResponseStatus(com.github.zhenwei.core.asn1.ocsp.OCSPResponseStatus) IOException(java.io.IOException) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString)

Example 44 with DEROctetString

use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.

the class JceOpenSSLPKCS8EncryptorBuilder method build.

public OutputEncryptor build() throws OperatorCreationException {
    final AlgorithmIdentifier algID;
    if (random == null) {
        random = new SecureRandom();
    }
    try {
        this.cipher = helper.createCipher(algOID.getId());
        if (PEMUtilities.isPKCS5Scheme2(algOID)) {
            this.paramGen = helper.createAlgorithmParameterGenerator(algOID.getId());
        }
    } catch (GeneralSecurityException e) {
        throw new OperatorCreationException(algOID + " not available: " + e.getMessage(), e);
    }
    if (PEMUtilities.isPKCS5Scheme2(algOID)) {
        salt = new byte[PEMUtilities.getSaltSize(prf.getAlgorithm())];
        random.nextBytes(salt);
        params = paramGen.generateParameters();
        try {
            EncryptionScheme scheme = new EncryptionScheme(algOID, ASN1Primitive.fromByteArray(params.getEncoded()));
            KeyDerivationFunc func = new KeyDerivationFunc(PKCSObjectIdentifiers.id_PBKDF2, new PBKDF2Params(salt, iterationCount, prf));
            ASN1EncodableVector v = new ASN1EncodableVector();
            v.add(func);
            v.add(scheme);
            algID = new AlgorithmIdentifier(PKCSObjectIdentifiers.id_PBES2, PBES2Parameters.getInstance(new DERSequence(v)));
        } catch (IOException e) {
            throw new OperatorCreationException(e.getMessage(), e);
        }
        try {
            if (PEMUtilities.isHmacSHA1(prf)) {
                key = PEMUtilities.generateSecretKeyForPKCS5Scheme2(helper, algOID.getId(), password, salt, iterationCount);
            } else {
                key = PEMUtilities.generateSecretKeyForPKCS5Scheme2(helper, algOID.getId(), password, salt, iterationCount, prf);
            }
            cipher.init(Cipher.ENCRYPT_MODE, key, params);
        } catch (GeneralSecurityException e) {
            throw new OperatorCreationException(e.getMessage(), e);
        }
    } else if (PEMUtilities.isPKCS12(algOID)) {
        ASN1EncodableVector v = new ASN1EncodableVector();
        salt = new byte[20];
        random.nextBytes(salt);
        v.add(new DEROctetString(salt));
        v.add(new ASN1Integer(iterationCount));
        algID = new AlgorithmIdentifier(algOID, PKCS12PBEParams.getInstance(new DERSequence(v)));
        try {
            cipher.init(Cipher.ENCRYPT_MODE, new PKCS12KeyWithParameters(password, salt, iterationCount));
        } catch (GeneralSecurityException e) {
            throw new OperatorCreationException(e.getMessage(), e);
        }
    } else {
        throw new OperatorCreationException("unknown algorithm: " + algOID, null);
    }
    return new OutputEncryptor() {

        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return algID;
        }

        public OutputStream getOutputStream(OutputStream encOut) {
            return new CipherOutputStream(encOut, cipher);
        }

        public GenericKey getKey() {
            return new JceGenericKey(algID, key);
        }
    };
}
Also used : EncryptionScheme(com.github.zhenwei.core.asn1.pkcs.EncryptionScheme) CipherOutputStream(com.github.zhenwei.provider.jcajce.io.CipherOutputStream) GeneralSecurityException(java.security.GeneralSecurityException) OutputStream(java.io.OutputStream) CipherOutputStream(com.github.zhenwei.provider.jcajce.io.CipherOutputStream) SecureRandom(java.security.SecureRandom) IOException(java.io.IOException) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) DERSequence(com.github.zhenwei.core.asn1.DERSequence) JceGenericKey(com.github.zhenwei.pkix.operator.jcajce.JceGenericKey) KeyDerivationFunc(com.github.zhenwei.core.asn1.pkcs.KeyDerivationFunc) PBKDF2Params(com.github.zhenwei.core.asn1.pkcs.PBKDF2Params) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) OperatorCreationException(com.github.zhenwei.pkix.operator.OperatorCreationException) PKCS12KeyWithParameters(com.github.zhenwei.provider.jcajce.PKCS12KeyWithParameters) OutputEncryptor(com.github.zhenwei.pkix.operator.OutputEncryptor)

Example 45 with DEROctetString

use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.

the class CVCertificateRequest method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    if (original != null) {
        return original;
    } else {
        ASN1EncodableVector v = new ASN1EncodableVector(2);
        v.add(certificateBody);
        try {
            v.add(new DERApplicationSpecific(false, EACTags.STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP, new DEROctetString(innerSignature)));
        } catch (IOException e) {
            throw new IllegalStateException("unable to convert signature!");
        }
        return new DERApplicationSpecific(EACTags.CARDHOLDER_CERTIFICATE, v);
    }
}
Also used : DERApplicationSpecific(com.github.zhenwei.core.asn1.DERApplicationSpecific) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) IOException(java.io.IOException) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString)

Aggregations

DEROctetString (org.bouncycastle.asn1.DEROctetString)139 IOException (java.io.IOException)104 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)86 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)49 DERSequence (org.bouncycastle.asn1.DERSequence)48 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)46 DERSequence (com.github.zhenwei.core.asn1.DERSequence)44 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)39 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)32 BigInteger (java.math.BigInteger)27 Extension (org.bouncycastle.asn1.x509.Extension)27 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)26 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)26 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)24 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)23 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)21 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)20 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)19 Extensions (org.bouncycastle.asn1.x509.Extensions)19 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)18