0

Well,

I need make api using java to encrypt, decrypt and another things about Cryptografy. I'm using bouncycastle framework to do. But I can't found Elliptic Curve Cryptigrafy Engine into BC Framework, I found RSAEngine, IESEngine.

I wanna encrypt with public key, and decrypt with private key, but all exemples that I found need both keys to encrypt, so I no understand it. Like it:

Security.addProvider(new BouncyCastleProvider());

    KeyPairGenerator kpg = (KeyPairGenerator) KeyPairGenerator.getInstance("ECIES", "BC");

    kpg.initialize(192, new SecureRandom());

    KeyPair keyPair = kpg.generateKeyPair();
    PublicKey pubKey = keyPair.getPublic();
    PrivateKey privKey = keyPair.getPrivate();

    byte[] d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8}; // 1. can someone tell me what this parameters does?
    byte[] e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1};

    IESParameterSpec param = new IESParameterSpec(d, e, 192); // 2. and this parameters?
    IEKeySpec c1Key = new IEKeySpec(privKey, pubKey);
    System.out.println(c1Key.getPublic());

    Cipher cipher = Cipher.getInstance("ECIES", "BC");
    cipher.init(Cipher.ENCRYPT_MODE, c1Key, param);
    System.out.println(cipher.doFinal("test12345678900987654321".getBytes()));

But in sometimes I no have private key, as encrypt with public key.

Someone help me?

Dimmy Magalhães
  • 357
  • 1
  • 6
  • 21

1 Answers1

0

Umm, as far as I know, ECC needs a different key for encrypting and decrypting. That's why it's called assymetric encryption.
Suppose Alice wants to send a message M(x,y) to Bob
1. The curve function is y^2 = x^3 + ax + b mod p with a reference point G(x,y)
2. Alice picks a private key nA and computes her public key Qa = nA.G
3. Bob picks a private key nB and computes his public key Qb = nB.G
4. Alice encrypts the message D = M + na.Qb (D = cipher text) and sends (Qa, D) to Bob
5. To decrypt the message, Bob computes M = D + (-nb).Qa and he recovers M

Hope this helps.

RedCrimson
  • 25
  • 6