use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.
the class ECGOST2012SignatureSpi256 method engineInitVerify.
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
ECKeyParameters param;
if (publicKey instanceof ECPublicKey) {
param = (ECKeyParameters) generatePublicKeyParameter(publicKey);
} else {
try {
byte[] bytes = publicKey.getEncoded();
publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
param = (ECKeyParameters) ECUtil.generatePublicKeyParameter(publicKey);
} catch (Exception e) {
throw new InvalidKeyException("cannot recognise key type in ECGOST-2012-256 signer");
}
}
if (param.getParameters().getN().bitLength() > 256) {
throw new InvalidKeyException("key out of range for ECGOST-2012-256");
}
digest.reset();
signer.init(false, param);
}
use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.
the class SignatureSpi method engineInitVerify.
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
CipherParameters param;
if (publicKey instanceof ECPublicKey) {
param = ECUtil.generatePublicKeyParameter(publicKey);
} else if (publicKey instanceof GOST3410Key) {
param = GOST3410Util.generatePublicKeyParameter(publicKey);
} else {
try {
byte[] bytes = publicKey.getEncoded();
publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
if (publicKey instanceof ECPublicKey) {
param = ECUtil.generatePublicKeyParameter(publicKey);
} else {
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
} catch (Exception e) {
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
}
digest.reset();
signer.init(false, param);
}
use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.
the class SignatureSpi method engineInitVerify.
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
CipherParameters param;
if (publicKey instanceof ECPublicKey) {
param = generatePublicKeyParameter(publicKey);
} else if (publicKey instanceof GOST3410Key) {
param = GOST3410Util.generatePublicKeyParameter(publicKey);
} else {
try {
byte[] bytes = publicKey.getEncoded();
publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
param = ECUtil.generatePublicKeyParameter(publicKey);
} catch (Exception e) {
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
}
digest.reset();
signer.init(false, param);
}
use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.
the class ECGOST2012SignatureSpi512 method engineInitVerify.
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
ECKeyParameters param;
if (publicKey instanceof ECPublicKey) {
param = (ECKeyParameters) generatePublicKeyParameter(publicKey);
} else {
try {
byte[] bytes = publicKey.getEncoded();
publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
param = (ECKeyParameters) ECUtil.generatePublicKeyParameter(publicKey);
} catch (Exception e) {
throw new InvalidKeyException("cannot recognise key type in ECGOST-2012-512 signer");
}
}
if (param.getParameters().getN().bitLength() < 505) {
throw new InvalidKeyException("key too weak for ECGOST-2012-512");
}
digest.reset();
signer.init(false, param);
}
use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.
the class ECUtil method generatePublicKeyParameter.
public static AsymmetricKeyParameter generatePublicKeyParameter(PublicKey key) throws InvalidKeyException {
if (key instanceof ECPublicKey) {
ECPublicKey k = (ECPublicKey) key;
ECParameterSpec s = k.getParameters();
return new ECPublicKeyParameters(k.getQ(), new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
} else if (key instanceof java.security.interfaces.ECPublicKey) {
java.security.interfaces.ECPublicKey pubKey = (java.security.interfaces.ECPublicKey) key;
ECParameterSpec s = EC5Util.convertSpec(pubKey.getParams());
return new ECPublicKeyParameters(EC5Util.convertPoint(pubKey.getParams(), pubKey.getW()), new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
} else {
// see if we can build a key from key.getEncoded()
try {
byte[] bytes = key.getEncoded();
if (bytes == null) {
throw new InvalidKeyException("no encoding for EC public key");
}
PublicKey publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
if (publicKey instanceof java.security.interfaces.ECPublicKey) {
return ECUtil.generatePublicKeyParameter(publicKey);
}
} catch (Exception e) {
throw new InvalidKeyException("cannot identify EC public key: " + e.toString());
}
}
throw new InvalidKeyException("cannot identify EC public key.");
}
Aggregations