11package  org .simplejavamail .utils .mail .dkim ;
22
3- import  java .nio .charset .StandardCharsets ;
43import  java .security .InvalidKeyException ;
54import  java .security .KeyFactory ;
65import  java .security .NoSuchAlgorithmException ;
6+ import  java .security .NoSuchProviderException ;
77import  java .security .PrivateKey ;
88import  java .security .PublicKey ;
99import  java .security .Signature ;
2020import  java .util .StringTokenizer ;
2121import  java .util .regex .Pattern ;
2222
23- import  net .i2p .crypto .eddsa .EdDSAPublicKey ;
24- import  net .i2p .crypto .eddsa .spec .EdDSANamedCurveTable ;
25- import  net .i2p .crypto .eddsa .spec .EdDSAPublicKeySpec ;
26- 
2723import  static  java .nio .charset .StandardCharsets .UTF_8 ;
2824
25+ import  org .bouncycastle .jcajce .interfaces .EdDSAPublicKey ;
26+ 
2927/** 
3028 * A {@code DomainKey} holds the information about a domain key. 
3129 *  
@@ -151,11 +149,10 @@ private RSAPublicKey getRsaPublicKey(String publicKeyTagValue) {
151149
152150   private  EdDSAPublicKey  getEd25519PublicKey (String  publicKeyTagValue ) {
153151      try  {
154-          KeyFactory  keyFactory  = KeyFactory .getInstance (KeyPairType .ED25519 .getJavaNotation ());
155-          EdDSAPublicKeySpec  publicKeySpec  = new  EdDSAPublicKeySpec (Base64 .getDecoder ().decode (publicKeyTagValue ),
156-                EdDSANamedCurveTable .ED_25519_CURVE_SPEC );
157-          return  (EdDSAPublicKey ) keyFactory .generatePublic (publicKeySpec );
158-       } catch  (NoSuchAlgorithmException  nsae ) {
152+          byte [] keyBytes  = Base64 .getDecoder ().decode (publicKeyTagValue );
153+          KeyFactory  keyFactory  = KeyFactory .getInstance (KeyPairType .ED25519 .getJavaNotation (), "BC" );
154+          return  (EdDSAPublicKey ) keyFactory .generatePublic (new  X509EncodedKeySpec (keyBytes ));
155+       } catch  (NoSuchAlgorithmException  | NoSuchProviderException  nsae ) {
159156         throw  new  DkimException ("Ed25519 algorithm not found by JVM" );
160157      } catch  (IllegalArgumentException  e ) {
161158         throw  new  DkimException ("The public key "  + publicKeyTagValue  + " couldn't be read." , e );
@@ -297,4 +294,4 @@ private void checkKeyCompatiblilty(PrivateKey privateKey)
297294
298295   }
299296
300- }
297+ }
0 commit comments