Generates a new public-private key pair for encryption and decryption. @param bits The size (in bits) of the keys to generate
(int bits)
| 89 | * @param bits The size (in bits) of the keys to generate |
| 90 | */ |
| 91 | public final void generateKeys(int bits) { |
| 92 | SecureRandom r = new SecureRandom(); |
| 93 | curve = new EllipticCurve(bits); // Initialize a new elliptic curve |
| 94 | basePoint = curve.getBasePoint(); // Set the base point G |
| 95 | |
| 96 | // Generate private key as a random BigInteger |
| 97 | privateKey = new BigInteger(bits, r); |
| 98 | |
| 99 | // Generate public key as the point publicKey = privateKey * G |
| 100 | publicKey = basePoint.multiply(privateKey, curve.getP(), curve.getA()); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Class representing an elliptic curve with the form y^2 = x^3 + ax + b. |
no test coverage detected