use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class McElieceKeyFactorySpi method engineGeneratePrivate.
/**
* Converts, if possible, a key specification into a {@link BCMcEliecePrivateKey}.
*
* @param keySpec the key specification
* @return the McEliece private key
* @throws InvalidKeySpecException if the KeySpec is not supported.
*/
protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
if (keySpec instanceof PKCS8EncodedKeySpec) {
// get the DER-encoded Key according to PKCS#8 from the spec
byte[] encKey = ((PKCS8EncodedKeySpec) keySpec).getEncoded();
// decode the PKCS#8 data structure to the pki object
PrivateKeyInfo pki;
try {
pki = PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
} catch (IOException e) {
throw new InvalidKeySpecException("Unable to decode PKCS8EncodedKeySpec: " + e);
}
try {
if (PQCObjectIdentifiers.mcEliece.equals(pki.getPrivateKeyAlgorithm().getAlgorithm())) {
McEliecePrivateKey key = McEliecePrivateKey.getInstance(pki.parsePrivateKey());
return new BCMcEliecePrivateKey(new McEliecePrivateKeyParameters(key.getN(), key.getK(), key.getField(), key.getGoppaPoly(), key.getP1(), key.getP2(), key.getSInv()));
} else {
throw new InvalidKeySpecException("Unable to recognise OID in McEliece private key");
}
} catch (IOException cce) {
throw new InvalidKeySpecException("Unable to decode PKCS8EncodedKeySpec.");
}
}
throw new InvalidKeySpecException("Unsupported key specification: " + keySpec.getClass() + ".");
}
use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class McElieceKeyFactorySpi method generatePrivate.
public PrivateKey generatePrivate(PrivateKeyInfo pki) throws IOException {
// get the inner type inside the BIT STRING
ASN1Primitive innerType = pki.parsePrivateKey().toASN1Primitive();
McEliecePrivateKey key = McEliecePrivateKey.getInstance(innerType);
return new BCMcEliecePrivateKey(new McEliecePrivateKeyParameters(key.getN(), key.getK(), key.getField(), key.getGoppaPoly(), key.getP1(), key.getP2(), key.getSInv()));
}
use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePrivateKeyParameters in project LinLong-Java by zhenwei1108.
the class McElieceKeyPairGeneratorSpi method generateKeyPair.
public KeyPair generateKeyPair() {
AsymmetricCipherKeyPair generateKeyPair = kpg.generateKeyPair();
McEliecePrivateKeyParameters sk = (McEliecePrivateKeyParameters) generateKeyPair.getPrivate();
McEliecePublicKeyParameters pk = (McEliecePublicKeyParameters) generateKeyPair.getPublic();
return new KeyPair(new BCMcEliecePublicKey(pk), new BCMcEliecePrivateKey(sk));
}
Aggregations