Search in sources :

Example 71 with DEROctetString

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

the class CCMParameters method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(2);
    v.add(new DEROctetString(nonce));
    if (icvLen != 12) {
        v.add(new ASN1Integer(icvLen));
    }
    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 72 with DEROctetString

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

the class SignatureSpiLe method engineSign.

protected byte[] engineSign() throws SignatureException {
    byte[] signature = ASN1OctetString.getInstance(super.engineSign()).getOctets();
    reverseBytes(signature);
    try {
        return (new DEROctetString(signature)).getEncoded();
    } catch (Exception e) {
        throw new SignatureException(e.toString());
    }
}
Also used : SignatureException(java.security.SignatureException) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) SignatureException(java.security.SignatureException) IOException(java.io.IOException)

Example 73 with DEROctetString

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

the class SignatureSpi method engineSign.

protected byte[] engineSign() throws SignatureException {
    byte[] hash = new byte[digest.getDigestSize()];
    digest.doFinal(hash, 0);
    try {
        BigInteger[] sig = signer.generateSignature(hash);
        byte[] r = sig[0].toByteArray();
        byte[] s = sig[1].toByteArray();
        byte[] sigBytes = new byte[(r.length > s.length ? r.length * 2 : s.length * 2)];
        System.arraycopy(s, 0, sigBytes, (sigBytes.length / 2) - s.length, s.length);
        System.arraycopy(r, 0, sigBytes, sigBytes.length - r.length, r.length);
        return new DEROctetString(sigBytes).getEncoded();
    } catch (Exception e) {
        throw new SignatureException(e.toString());
    }
}
Also used : BigInteger(java.math.BigInteger) SignatureException(java.security.SignatureException) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 74 with DEROctetString

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

the class BCDSTU4145PublicKey method getEncoded.

public byte[] getEncoded() {
    ASN1Encodable params;
    SubjectPublicKeyInfo info;
    if (dstuParams != null) {
        params = dstuParams;
    } else {
        if (ecSpec instanceof ECNamedCurveSpec) {
            params = new DSTU4145Params(new ASN1ObjectIdentifier(((ECNamedCurveSpec) ecSpec).getName()));
        } else {
            // strictly speaking this may not be applicable...
            ECCurve curve = EC5Util.convertCurve(ecSpec.getCurve());
            X9ECParameters ecP = new X9ECParameters(curve, new X9ECPoint(EC5Util.convertPoint(curve, ecSpec.getGenerator()), withCompression), ecSpec.getOrder(), BigInteger.valueOf(ecSpec.getCofactor()), ecSpec.getCurve().getSeed());
            params = new X962Parameters(ecP);
        }
    }
    // NOTE: 'withCompression' is ignored here
    byte[] encKey = DSTU4145PointEncoder.encodePoint(ecPublicKey.getQ());
    try {
        info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(UAObjectIdentifiers.dstu4145be, params), new DEROctetString(encKey));
    } catch (IOException e) {
        return null;
    }
    return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
}
Also used : X9ECParameters(com.github.zhenwei.core.asn1.x9.X9ECParameters) IOException(java.io.IOException) SubjectPublicKeyInfo(com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo) DSTU4145Params(com.github.zhenwei.core.asn1.ua.DSTU4145Params) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) X962Parameters(com.github.zhenwei.core.asn1.x9.X962Parameters) X9ECPoint(com.github.zhenwei.core.asn1.x9.X9ECPoint) ECCurve(com.github.zhenwei.core.math.ec.ECCurve) ASN1Encodable(com.github.zhenwei.core.asn1.ASN1Encodable) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier) ECNamedCurveSpec(com.github.zhenwei.provider.jce.spec.ECNamedCurveSpec)

Example 75 with DEROctetString

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

the class SspRange method getInstance.

public static SspRange getInstance(Object src) {
    if (src instanceof SspRange) {
        return (SspRange) src;
    }
    ASN1TaggedObject taggedObject = ASN1TaggedObject.getInstance(src);
    int item = taggedObject.getTagNo();
    switch(item) {
        case opaque:
            return new SspRange(opaque, SequenceOfOctetString.getInstance(taggedObject.getObject()));
        case all:
            return new SspRange(all, DERNull.INSTANCE);
        case extension:
            try {
                return new SspRange(extension, new DEROctetString(taggedObject.getObject().getEncoded()));
            } catch (IOException ioException) {
                throw new RuntimeException(ioException.getMessage(), ioException);
            }
        case bitmapSspRange:
            return new SspRange(bitmapSspRange, BitmapSspRange.getInstance(taggedObject.getObject()));
    }
    throw new IllegalStateException("unknown choice " + item);
}
Also used : ASN1TaggedObject(com.github.zhenwei.core.asn1.ASN1TaggedObject) 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