use of com.github.zhenwei.provider.jcajce.spec.DHDomainParameterSpec in project LinLong-Java by zhenwei1108.
the class BouncyCastleProviderConfiguration method getDHDefaultParameters.
public DHParameterSpec getDHDefaultParameters(int keySize) {
Object params = dhThreadSpec.get();
if (params == null) {
params = dhDefaultParams;
}
if (params instanceof DHParameterSpec) {
DHParameterSpec spec = (DHParameterSpec) params;
if (spec.getP().bitLength() == keySize) {
return spec;
}
} else if (params instanceof DHParameterSpec[]) {
DHParameterSpec[] specs = (DHParameterSpec[]) params;
for (int i = 0; i != specs.length; i++) {
if (specs[i].getP().bitLength() == keySize) {
return specs[i];
}
}
}
DHParameters dhParams = CryptoServicesRegistrar.getSizedProperty(CryptoServicesRegistrar.Property.DH_DEFAULT_PARAMS, keySize);
if (dhParams != null) {
return new DHDomainParameterSpec(dhParams);
}
return null;
}
use of com.github.zhenwei.provider.jcajce.spec.DHDomainParameterSpec 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;
}
}
use of com.github.zhenwei.provider.jcajce.spec.DHDomainParameterSpec 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));
}
use of com.github.zhenwei.provider.jcajce.spec.DHDomainParameterSpec in project LinLong-Java by zhenwei1108.
the class KeyAgreementSpi method generatePublicKeyParameter.
private DHPublicKeyParameters generatePublicKeyParameter(PublicKey pubKey) throws InvalidKeyException {
if (pubKey instanceof DHPublicKey) {
if (pubKey instanceof BCDHPublicKey) {
return ((BCDHPublicKey) pubKey).engineGetKeyParameters();
} else {
DHPublicKey pub = (DHPublicKey) pubKey;
DHParameterSpec params = pub.getParams();
if (params instanceof DHDomainParameterSpec) {
return new DHPublicKeyParameters(pub.getY(), ((DHDomainParameterSpec) params).getDomainParameters());
}
return new DHPublicKeyParameters(pub.getY(), new DHParameters(params.getP(), params.getG(), null, params.getL()));
}
} else {
throw new InvalidKeyException("public key not a DHPublicKey");
}
}
Aggregations