Encrypts the message using the public key. The message is transformed into an ECPoint and encrypted with elliptic curve operations. @param message The plain message to be encrypted @return The encrypted message as an array of ECPoints (R, S)
(String message)
| 51 | * @return The encrypted message as an array of ECPoints (R, S) |
| 52 | */ |
| 53 | public ECPoint[] encrypt(String message) { |
| 54 | BigInteger m = new BigInteger(message.getBytes()); // Convert message to BigInteger |
| 55 | SecureRandom r = new SecureRandom(); // Generate random value for k |
| 56 | BigInteger k = new BigInteger(curve.getFieldSize(), r); // Generate random scalar k |
| 57 | |
| 58 | // Calculate point r = k * G, where G is the base point |
| 59 | ECPoint rPoint = basePoint.multiply(k, curve.getP(), curve.getA()); |
| 60 | |
| 61 | // Calculate point s = k * publicKey + encodedMessage |
| 62 | ECPoint sPoint = publicKey.multiply(k, curve.getP(), curve.getA()).add(curve.encodeMessage(m), curve.getP(), curve.getA()); |
| 63 | |
| 64 | return new ECPoint[] {rPoint, sPoint}; // Return encrypted message as two ECPoints |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Decrypts the encrypted message using the private key. |
nothing calls this directly
no test coverage detected