我想序列化 McEliece 公钥 (BCMcEliecePublicKey),但总是得到 NotSerializableException。
java.io.NotSerializableException: org.bouncycastle.pqc.crypto.mceliece.McEliecePublicKeyParameters
我用 XMSSMT 尝试了相同的代码,它没有问题。Bouncy Castle 版本是新的 Release 1.61
这里以一个小代码为例:
//key generation
Security.addProvider(new BouncyCastlePQCProvider());
KeyPairGenerator keygen = null;
try {
keygen = KeyPairGenerator.getInstance("McEliece", "BCPQC"); //XMSSMT
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
System.out.println("Error: KeyPairGenerator could not be instanciated. " + e.getMessage());
}
//XMSSMTParameterSpec bcSpec = new XMSSMTParameterSpec(10, 5, XMSSMTParameterSpec.SHA256);
McElieceKeyGenParameterSpec bcSpec = new McElieceKeyGenParameterSpec();
try {
keygen.initialize(bcSpec, new SecureRandom());
} catch (InvalidAlgorithmParameterException e) {
System.out.println("Error: Initialize failed. " + e.getMessage());
}
PublicKey pub = keygen.generateKeyPair().getPublic();
//BCMcEliecePublicKey pubMcEliece = (BCMcEliecePublicKey) pub;
//McEliecePublicKeyParameters keyParameters = new McEliecePublicKeyParameters(pubMcEliece.getN(), pubMcEliece.getT(), pubMcEliece.getG());
//serialization
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(pub); //keyParameters
System.out.println("OK");
} catch (IOException e) {
System.out.println(e);
}
我必须更改什么才能序列化密钥?