0

J'essaie actuellement d'implémenter le cryptage McEliece en utilisant BC mais en rencontrant quelques problèmes. J'ai actuellement les possibilités pour créer les clefs et les placer dans un dossier, je peux les relire dans le programme mais ne peux pas l'obtenir pour retourner des octets à la clef publique.McEliece (Bouncy Castle) Récupérer la clé publique

Ci-dessous ce que j'ai actuellement:

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

L'im d'erreur de courant ayant avec ce code est le KeyFactory et que « McEliece » est pas considéré comme un algorithme comme im obtenir NoSuchAlgorithmException mais je ne suis pas vraiment sûr de ce que d'autre pour essayer en ce moment. J'ai également essayé d'utiliser le KeyFactory qui est inclus avec BouncyCastle pour McEliece mais n'a pas eu de succès car les méthodes étaient protégées ou ne permettaient pas KeySpec et voulaient SubjectPublicKeyInfo que je ne pouvais pas comprendre comment changer KeySpec dans ou le tableau Byte dans.

Désolé si c'est une question simple im assez nouveau à la cryptographie de codage.

Merci pour les réponses à l'avance.

Répondre

1

Géré pour comprendre le problème. J'avais besoin d'ajouter:

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

Merci de rendre compte MrFolo, vous pouvez accepter votre propre réponse après un certain temps (un jour ou 2 si je ne me trompe pas). –