Skip to content

Commit

Permalink
Merge branch 'desyncr-freenet-bc-patch' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBab committed Oct 10, 2018
2 parents 1d03c5b + fc04181 commit 3273c71
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/freenet/crypt/KeyGenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
*/
public final class KeyGenUtils {

static {
java.security.Security.insertProviderAt(new BouncyCastleProvider(), 1);
}

/**
* Generates a public/private key pair formatted for the algorithm specified
* and stores the keys in a KeyPair. Can not handle DSA keys.
Expand All @@ -47,7 +51,7 @@ public static KeyPair genKeyPair(KeyPairType type) {
throw new UnsupportedTypeException(type);
}
try {
KeyPairGenerator kg = KeyPairGenerator.getInstance(type.alg, new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance(type.alg);
kg.initialize(type.spec);
return kg.generateKeyPair();
} catch (NoSuchAlgorithmException e) {
Expand All @@ -68,7 +72,7 @@ public static PublicKey getPublicKey(KeyPairType type, byte[] pub){
throw new UnsupportedTypeException(type);
}
try {
KeyFactory kf = KeyFactory.getInstance(type.alg, new BouncyCastleProvider());
KeyFactory kf = KeyFactory.getInstance(type.alg);
X509EncodedKeySpec xks = new X509EncodedKeySpec(pub);
return kf.generatePublic(xks);
} catch (NoSuchAlgorithmException e) {
Expand Down Expand Up @@ -123,7 +127,7 @@ public static KeyPair getKeyPair(KeyPairType type, byte[] pub, byte[] pri) {
throw new UnsupportedTypeException(type);
}
try {
KeyFactory kf = KeyFactory.getInstance(type.alg, new BouncyCastleProvider());
KeyFactory kf = KeyFactory.getInstance(type.alg);

PublicKey pubK = getPublicKey(type, pub);

Expand Down Expand Up @@ -170,7 +174,7 @@ public static KeyPair getKeyPair(PublicKey pubK, PrivateKey privK){
*/
public static SecretKey genSecretKey(KeyType type){
try{
KeyGenerator kg = KeyGenerator.getInstance(type.alg, new BouncyCastleProvider());
KeyGenerator kg = KeyGenerator.getInstance(type.alg);
kg.init(type.keySize);
return kg.generateKey();
} catch (NoSuchAlgorithmException e) {
Expand Down

0 comments on commit 3273c71

Please sign in to comment.