use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.
the class KeyPairGeneratorSpi method generateKeyPair.
public KeyPair generateKeyPair() {
if (!initialised) {
init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), CryptoServicesRegistrar.getSecureRandom());
}
AsymmetricCipherKeyPair pair = engine.generateKeyPair();
GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters) pair.getPublic();
GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters) pair.getPrivate();
return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.
the class AlgorithmParameterGeneratorSpi method engineGenerateParameters.
protected AlgorithmParameters engineGenerateParameters() {
GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator();
if (random != null) {
pGen.init(strength, 2, random);
} else {
pGen.init(strength, 2, CryptoServicesRegistrar.getSecureRandom());
}
GOST3410Parameters p = pGen.generateParameters();
AlgorithmParameters params;
try {
params = createParametersInstance("GOST3410");
params.init(new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec(p.getP(), p.getQ(), p.getA())));
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return params;
}
use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.
the class BCGOST3410PrivateKey method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
String publicKeyParamSetOID = (String) in.readObject();
if (publicKeyParamSetOID != null) {
this.gost3410Spec = new GOST3410ParameterSpec(publicKeyParamSetOID, (String) in.readObject(), (String) in.readObject());
} else {
this.gost3410Spec = new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec((BigInteger) in.readObject(), (BigInteger) in.readObject(), (BigInteger) in.readObject()));
in.readObject();
in.readObject();
}
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
}
use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.
the class BCGOST3410PublicKey method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
String publicKeyParamSetOID = (String) in.readObject();
if (publicKeyParamSetOID != null) {
this.gost3410Spec = new GOST3410ParameterSpec(publicKeyParamSetOID, (String) in.readObject(), (String) in.readObject());
} else {
this.gost3410Spec = new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec((BigInteger) in.readObject(), (BigInteger) in.readObject(), (BigInteger) in.readObject()));
in.readObject();
in.readObject();
}
}
use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.
the class BCGOST3410PublicKey method getEncoded.
public byte[] getEncoded() {
SubjectPublicKeyInfo info;
byte[] keyEnc = this.getY().toByteArray();
byte[] keyBytes;
if (keyEnc[0] == 0) {
keyBytes = new byte[keyEnc.length - 1];
} else {
keyBytes = new byte[keyEnc.length];
}
for (int i = 0; i != keyBytes.length; i++) {
// must be little endian
keyBytes[i] = keyEnc[keyEnc.length - 1 - i];
}
try {
if (gost3410Spec instanceof GOST3410ParameterSpec) {
if (gost3410Spec.getEncryptionParamSetOID() != null) {
info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getEncryptionParamSetOID()))), new DEROctetString(keyBytes));
} else {
info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()))), new DEROctetString(keyBytes));
}
} else {
info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94), new DEROctetString(keyBytes));
}
return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
} catch (IOException e) {
return null;
}
}
Aggregations