1
1
package org .simplejavamail .utils .mail .dkim ;
2
2
3
- import java .nio .charset .StandardCharsets ;
4
3
import java .security .InvalidKeyException ;
5
4
import java .security .KeyFactory ;
6
5
import java .security .NoSuchAlgorithmException ;
6
+ import java .security .NoSuchProviderException ;
7
7
import java .security .PrivateKey ;
8
8
import java .security .PublicKey ;
9
9
import java .security .Signature ;
20
20
import java .util .StringTokenizer ;
21
21
import java .util .regex .Pattern ;
22
22
23
- import net .i2p .crypto .eddsa .EdDSAPublicKey ;
24
- import net .i2p .crypto .eddsa .spec .EdDSANamedCurveTable ;
25
- import net .i2p .crypto .eddsa .spec .EdDSAPublicKeySpec ;
26
-
27
23
import static java .nio .charset .StandardCharsets .UTF_8 ;
28
24
25
+ import org .bouncycastle .jcajce .interfaces .EdDSAPublicKey ;
26
+
29
27
/**
30
28
* A {@code DomainKey} holds the information about a domain key.
31
29
*
@@ -151,11 +149,10 @@ private RSAPublicKey getRsaPublicKey(String publicKeyTagValue) {
151
149
152
150
private EdDSAPublicKey getEd25519PublicKey (String publicKeyTagValue ) {
153
151
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 ) {
159
156
throw new DkimException ("Ed25519 algorithm not found by JVM" );
160
157
} catch (IllegalArgumentException e ) {
161
158
throw new DkimException ("The public key " + publicKeyTagValue + " couldn't be read." , e );
@@ -297,4 +294,4 @@ private void checkKeyCompatiblilty(PrivateKey privateKey)
297
294
298
295
}
299
296
300
- }
297
+ }
0 commit comments