MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / generateKeys

Method generateKeys

src/main/java/com/thealgorithms/ciphers/ECC.java:91–101  ·  view source on GitHub ↗

Generates a new public-private key pair for encryption and decryption. @param bits The size (in bits) of the keys to generate

(int bits)

Source from the content-addressed store, hash-verified

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.

Callers 1

ECCMethod · 0.95

Calls 4

getBasePointMethod · 0.80
getPMethod · 0.80
getAMethod · 0.80
multiplyMethod · 0.45

Tested by

no test coverage detected