0

현재 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; 
}\ 

이 코드를 갖는 현재의 에러 메신저는 KeyFactory에 함께와 "McEliece이"는 않고 NoSuchAlgorithmException를 받고 메신저 같은 알고리즘하지만 정말 확실하지 메신저로 간주되지 않는 것입니다 무엇을 그 순간에 시도해보십시오. 나는 또한 McEliece에 BouncyCastle에 포함 된 KeyFactory를 사용하려고 시도했으나 메서드가 보호되었거나 KeySpec을 허용하지 않고 KeyPpec 또는 Byte 배열을 변경하는 방법을 알 수없는 SubjectPublicKeyInfo를 원했기 때문에 성공하지 못했습니다. 으로.

죄송합니다. 간단한 질문인데 죄송합니다. 암호화를 코딩하는 데 새로운 것이 있습니다.

답장을 미리 보내 주셔서 감사합니다.

답변

1

문제를 해결할 관리. 내가 추가해야했습니다 :

  Security.addProvider(new BouncyCastleProvider()); 
      Security.addProvider(new BouncyCastlePQCProvider()); 
+0

MrFolo을 (를)보고 해 주셔서 감사합니다. 잠시 후 (내가 실수하지 않은 경우) 하루 만의 답변을 수락 할 수 있습니다. –