Search in sources :

Example 1 with DHValidationParameters

use of com.github.zhenwei.core.crypto.params.DHValidationParameters 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 2 with DHValidationParameters

use of com.github.zhenwei.core.crypto.params.DHValidationParameters 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 3 with DHValidationParameters

use of com.github.zhenwei.core.crypto.params.DHValidationParameters in project LinLong-Java by zhenwei1108.

the class CryptoServicesRegistrar method toDH.

private static DHParameters toDH(DSAParameters dsaParams) {
    int pSize = dsaParams.getP().bitLength();
    int m = chooseLowerBound(pSize);
    return new DHParameters(dsaParams.getP(), dsaParams.getG(), dsaParams.getQ(), m, 0, null, new DHValidationParameters(dsaParams.getValidationParameters().getSeed(), dsaParams.getValidationParameters().getCounter()));
}
Also used : DHParameters(com.github.zhenwei.core.crypto.params.DHParameters) DHValidationParameters(com.github.zhenwei.core.crypto.params.DHValidationParameters)

Aggregations

DHParameters (com.github.zhenwei.core.crypto.params.DHParameters)3 DHValidationParameters (com.github.zhenwei.core.crypto.params.DHValidationParameters)3 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)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 DHDomainParameterSpec (com.github.zhenwei.provider.jcajce.spec.DHDomainParameterSpec)2 PrivateKeyInfo (com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo)1 IOException (java.io.IOException)1