Bouncy Castle not working on linux machine

2019-05-21 02:28发布

问题:

I implemented boucnyCastle for fips complaint signature generation and verification, this worked fine on a windows environment but on a linux environment the code is stuck on keypair generation. Following is the code that i have written:

public static KeyPair generateKeyPair() throws GeneralSecurityException
{
    KeyPairGenerator keyPair = KeyPairGenerator.getInstance("RSA", "BCFIPS");
    keyPair.initialize(new RSAKeyGenParameterSpec(3072, RSAKeyGenParameterSpec.F4));
    return keyPair.generateKeyPair();
}

Bouncy Castle

回答1:

First Check if rngd.service (Hardware RNG Entropy Gatherer Daemon) is running on your system. If you are using Virtual Machine then it will not be running and to fix it use the following link:

http://wiki.networksecuritytoolkit.org/index.php/HowTo_Fix_The_rngd.service

Second check if your system has enough entropy using command:

cat /proc/sys/kernel/random/entropy_avail

if Entropy of your system has not enough Entropy then increase it. you can use the following link:

https://redhatlinux.guru/index.php/2016/04/03/increase-system-entropy-on-rhel-centos-6-and-7/

Also Install Haveged on your system to generate artificial entropy. To install Haveged you can use the following link:

https://www.digitalocean.com/community/tutorials/how-to-setup-additional-entropy-for-cloud-servers-using-haveged