McEliece(Bouncy Castle)获取公钥返回
问题描述:
我目前正在尝试使用BC实现McEliece加密,但遇到了一些麻烦。我目前有能力创建密钥并将它们放置到文件中,我可以将它们读回到程序中,但无法从字节回到公钥。McEliece(Bouncy Castle)获取公钥返回
下面是我目前有:
public static String EncryptText(Component tmp, String Plaintext) throws InvalidKeyException, InvalidCipherTextException {
String CipherText = "Didnt Work";
try {
// The message to encrypt.
byte[] messageBytes = Plaintext.getBytes();
//read in the Public Key to use to Encrypt.
File f = new File(tmp.getPublicKey());
FileInputStream fis = new FileInputStream(f);
byte[] PubKeybytes = new byte[fis.available()];
fis.read(PubKeybytes);
fis.close();
//turn the bytes into the Key.
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(PubKeybytes);
SubjectPublicKeyInfo PKI ;
KeyFactory KF = null;
try {
KF = KeyFactory.getInstance("McEliece");
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(McEliecePKCS.class.getName()).log(Level.SEVERE, null, ex);
}
PublicKey PK = null;
try {
PK = KF.generatePublic(pubKeySpec);
} catch (InvalidKeySpecException ex) {
Logger.getLogger(McEliecePKCS.class.getName()).log(Level.SEVERE, null, ex);
}
//Public Key
PublicKey aPublic = PK;
McEliecePublicKeyParameters GPKP = (McEliecePublicKeyParameters) McElieceKeysToParams.generatePublicKeyParameter(aPublic);
//set the public key to use.
McElieceCipher EnCipheredText = new McElieceCipher();
EnCipheredText.init(true, GPKP);
EnCipheredText.initCipherEncrypt(GPKP);
byte[] ciphertextBytes;
//sign the message with the public key.
ciphertextBytes = EnCipheredText.messageEncrypt(messageBytes);
CipherText = new String(ciphertextBytes);
return CipherText;
} catch (IOException ex) {
Logger.getLogger(McEliecePKCS.class.getName()).log(Level.SEVERE, null, ex);
}
return CipherText;
}\
与此代码具有当前误差IM与的KeyFactory和“McEliece公钥体制”不认为是算法即时得到抛出:NoSuchAlgorithmException,但我不是很确定什么别的现在就试试。我也尝试过使用BouncyCastle包含的McEliece中的KeyFactory,但没有成功,因为这些方法是受保护的,或者不允许使用KeySpec,并且想要SubjectPublicKeyInfo,我无法弄清楚如何将KeySpec改成Byte数组成。
对不起,如果这是一个简单的问题,相当新的编码密码学。
感谢您提前回复。
答
管理找出问题。我需要补充:
Security.addProvider(new BouncyCastleProvider());
Security.addProvider(new BouncyCastlePQCProvider());
感谢您报告返回MrFolo,你可以在一段时间后接受你自己的答案(如果我没有弄错,一天或2天)。 –