use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters in project LinLong-Java by zhenwei1108.
the class McElieceKeyFactorySpi method generatePublic.
public PublicKey generatePublic(SubjectPublicKeyInfo pki) throws IOException {
// get the inner type inside the BIT STRING
ASN1Primitive innerType = pki.parsePublicKey();
McEliecePublicKey key = McEliecePublicKey.getInstance(innerType);
return new BCMcEliecePublicKey(new McEliecePublicKeyParameters(key.getN(), key.getT(), key.getG()));
}
use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters in project LinLong-Java by zhenwei1108.
the class McElieceKeyFactorySpi method engineGeneratePublic.
/**
* Converts, if possible, a key specification into a {@link BCMcEliecePublicKey}. {@link
* X509EncodedKeySpec}.
*
* @param keySpec the key specification
* @return the McEliece public key
* @throws InvalidKeySpecException if the key specification is not supported.
*/
protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException {
if (keySpec instanceof X509EncodedKeySpec) {
// get the DER-encoded Key according to X.509 from the spec
byte[] encKey = ((X509EncodedKeySpec) keySpec).getEncoded();
// decode the SubjectPublicKeyInfo data structure to the pki object
SubjectPublicKeyInfo pki;
try {
pki = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
} catch (IOException e) {
throw new InvalidKeySpecException(e.toString());
}
try {
if (PQCObjectIdentifiers.mcEliece.equals(pki.getAlgorithm().getAlgorithm())) {
McEliecePublicKey key = McEliecePublicKey.getInstance(pki.parsePublicKey());
return new BCMcEliecePublicKey(new McEliecePublicKeyParameters(key.getN(), key.getT(), key.getG()));
} else {
throw new InvalidKeySpecException("Unable to recognise OID in McEliece public key");
}
} catch (IOException cce) {
throw new InvalidKeySpecException("Unable to decode X509EncodedKeySpec: " + cce.getMessage());
}
}
throw new InvalidKeySpecException("Unsupported key specification: " + keySpec.getClass() + ".");
}
use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters 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