Search in sources :

Example 6 with DomainParameters

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

the class ECUtil method getDomainParameters.

public static ECDomainParameters getDomainParameters(ProviderConfiguration configuration, com.github.zhenwei.provider.jce.spec.ECParameterSpec params) {
    ECDomainParameters domainParameters;
    if (params instanceof ECNamedCurveParameterSpec) {
        ECNamedCurveParameterSpec nParams = (ECNamedCurveParameterSpec) params;
        ASN1ObjectIdentifier nameOid = ECUtil.getNamedCurveOid(nParams.getName());
        domainParameters = new ECNamedDomainParameters(nameOid, nParams.getCurve(), nParams.getG(), nParams.getN(), nParams.getH(), nParams.getSeed());
    } else if (params == null) {
        com.github.zhenwei.provider.jce.spec.ECParameterSpec iSpec = configuration.getEcImplicitlyCa();
        domainParameters = new ECDomainParameters(iSpec.getCurve(), iSpec.getG(), iSpec.getN(), iSpec.getH(), iSpec.getSeed());
    } else {
        domainParameters = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());
    }
    return domainParameters;
}
Also used : ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) ECParameterSpec(com.github.zhenwei.provider.jce.spec.ECParameterSpec) ECNamedCurveParameterSpec(com.github.zhenwei.provider.jce.spec.ECNamedCurveParameterSpec) ECNamedDomainParameters(com.github.zhenwei.core.crypto.params.ECNamedDomainParameters) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)

Example 7 with DomainParameters

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

the class BCDHPrivateKey method getEncoded.

/**
 * Return a PKCS8 representation of the key. The sequence returned represents a full
 * PrivateKeyInfo object.
 *
 * @return a PKCS8 representation of the key.
 */
public byte[] getEncoded() {
    try {
        if (info != null) {
            return info.getEncoded(ASN1Encoding.DER);
        }
        PrivateKeyInfo info;
        if (dhSpec instanceof DHDomainParameterSpec && ((DHDomainParameterSpec) dhSpec).getQ() != null) {
            DHParameters params = ((DHDomainParameterSpec) dhSpec).getDomainParameters();
            DHValidationParameters validationParameters = params.getValidationParameters();
            ValidationParams vParams = null;
            if (validationParameters != null) {
                vParams = new ValidationParams(validationParameters.getSeed(), validationParameters.getCounter());
            }
            info = new PrivateKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.dhpublicnumber, new DomainParameters(params.getP(), params.getG(), params.getQ(), params.getJ(), vParams).toASN1Primitive()), new ASN1Integer(getX()));
        } else {
            info = new PrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.dhKeyAgreement, new DHParameter(dhSpec.getP(), dhSpec.getG(), dhSpec.getL()).toASN1Primitive()), new ASN1Integer(getX()));
        }
        return info.getEncoded(ASN1Encoding.DER);
    } catch (Exception e) {
        return null;
    }
}
Also used : DHDomainParameterSpec(com.github.zhenwei.provider.jcajce.spec.DHDomainParameterSpec) DHParameters(com.github.zhenwei.core.crypto.params.DHParameters) DHValidationParameters(com.github.zhenwei.core.crypto.params.DHValidationParameters) ValidationParams(com.github.zhenwei.core.asn1.x9.ValidationParams) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) DHParameter(com.github.zhenwei.core.asn1.pkcs.DHParameter) PrivateKeyInfo(com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo) IOException(java.io.IOException) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) DomainParameters(com.github.zhenwei.core.asn1.x9.DomainParameters)

Example 8 with DomainParameters

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

the class BCDHPublicKey method getEncoded.

public byte[] getEncoded() {
    if (info != null) {
        return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
    }
    if (dhSpec instanceof DHDomainParameterSpec && ((DHDomainParameterSpec) dhSpec).getQ() != null) {
        DHParameters params = ((DHDomainParameterSpec) dhSpec).getDomainParameters();
        DHValidationParameters validationParameters = params.getValidationParameters();
        ValidationParams vParams = null;
        if (validationParameters != null) {
            vParams = new ValidationParams(validationParameters.getSeed(), validationParameters.getCounter());
        }
        return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.dhpublicnumber, new DomainParameters(params.getP(), params.getG(), params.getQ(), params.getJ(), vParams).toASN1Primitive()), new ASN1Integer(y));
    }
    return KeyUtil.getEncodedSubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.dhKeyAgreement, new DHParameter(dhSpec.getP(), dhSpec.getG(), dhSpec.getL()).toASN1Primitive()), new ASN1Integer(y));
}
Also used : DHDomainParameterSpec(com.github.zhenwei.provider.jcajce.spec.DHDomainParameterSpec) DHParameters(com.github.zhenwei.core.crypto.params.DHParameters) DHValidationParameters(com.github.zhenwei.core.crypto.params.DHValidationParameters) ValidationParams(com.github.zhenwei.core.asn1.x9.ValidationParams) ASN1Integer(com.github.zhenwei.core.asn1.ASN1Integer) DHParameter(com.github.zhenwei.core.asn1.pkcs.DHParameter) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) DomainParameters(com.github.zhenwei.core.asn1.x9.DomainParameters)

Example 9 with DomainParameters

use of com.github.zhenwei.core.asn1.x9.DomainParameters in project jiguang-java-client-common by jpush.

the class BCECUtil method getDomainParametersFromName.

/**
 * copy from BC
 *
 * @param curveName
 * @return
 */
public static X9ECParameters getDomainParametersFromName(String curveName) {
    X9ECParameters domainParameters;
    try {
        if (curveName.charAt(0) >= '0' && curveName.charAt(0) <= '2') {
            ASN1ObjectIdentifier oidID = new ASN1ObjectIdentifier(curveName);
            domainParameters = ECUtil.getNamedCurveByOid(oidID);
        } else {
            if (curveName.indexOf(' ') > 0) {
                curveName = curveName.substring(curveName.indexOf(' ') + 1);
                domainParameters = ECUtil.getNamedCurveByName(curveName);
            } else {
                domainParameters = ECUtil.getNamedCurveByName(curveName);
            }
        }
    } catch (IllegalArgumentException ex) {
        domainParameters = ECUtil.getNamedCurveByName(curveName);
    }
    return domainParameters;
}
Also used : X9ECParameters(org.bouncycastle.asn1.x9.X9ECParameters) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 10 with DomainParameters

use of com.github.zhenwei.core.asn1.x9.DomainParameters in project opb-sdk-java by bianjieai.

the class BCECUtils method getDomainParametersFromName.

/**
 * copy from BC
 *
 * @param curveName
 * @return
 */
public static X9ECParameters getDomainParametersFromName(String curveName) {
    X9ECParameters domainParameters;
    try {
        if (curveName.charAt(0) >= '0' && curveName.charAt(0) <= '2') {
            ASN1ObjectIdentifier oidID = new ASN1ObjectIdentifier(curveName);
            domainParameters = ECUtil.getNamedCurveByOid(oidID);
        } else {
            if (curveName.indexOf(' ') > 0) {
                curveName = curveName.substring(curveName.indexOf(' ') + 1);
                domainParameters = ECUtil.getNamedCurveByName(curveName);
            } else {
                domainParameters = ECUtil.getNamedCurveByName(curveName);
            }
        }
    } catch (IllegalArgumentException ex) {
        domainParameters = ECUtil.getNamedCurveByName(curveName);
    }
    return domainParameters;
}
Also used : X9ECParameters(org.bouncycastle.asn1.x9.X9ECParameters) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)4 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)3 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)2 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)2 DHParameter (com.github.zhenwei.core.asn1.pkcs.DHParameter)2 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)2 DomainParameters (com.github.zhenwei.core.asn1.x9.DomainParameters)2 ValidationParams (com.github.zhenwei.core.asn1.x9.ValidationParams)2 DHParameters (com.github.zhenwei.core.crypto.params.DHParameters)2 DHValidationParameters (com.github.zhenwei.core.crypto.params.DHValidationParameters)2 ECDomainParameters (com.github.zhenwei.core.crypto.params.ECDomainParameters)2 ECNamedDomainParameters (com.github.zhenwei.core.crypto.params.ECNamedDomainParameters)2 DHDomainParameterSpec (com.github.zhenwei.provider.jcajce.spec.DHDomainParameterSpec)2 ECParameterSpec (com.github.zhenwei.provider.jce.spec.ECParameterSpec)2 Map (java.util.Map)2 X9ECPoint (org.bouncycastle.asn1.x9.X9ECPoint)2 ECDomainParameters (org.bouncycastle.crypto.params.ECDomainParameters)2 ECPublicKeyParameters (org.bouncycastle.crypto.params.ECPublicKeyParameters)2 ECPoint (org.bouncycastle.math.ec.ECPoint)2 PrivateKeyInfo (com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo)1