好吧,
我需要使用java进行api加密,解密和Cryptografy的其他事情。我正在使用bouncycastle框架来做。但是我找不到Elliptic Curve Cryptigrafy Engine进入BC Framework,我找到了RSAEngine,IESEngine。
我想用公钥加密,并用私钥解密,但我发现的所有例子都需要两个加密密钥,所以我不明白。喜欢它:
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()));
但有时我没有私钥,用公钥加密。
有人帮助我吗?
答案 0 :(得分:0)
y^2 = x^3 + ax + b mod p
,参考点为G(x,y)
nA
并计算她的公钥Qa = nA.G
nB
并计算他的公钥Qb = nB.G
D = M + na.Qb
(D =密文)并将(Qa, D)
发送给Bob
5.为了解密消息,Bob计算M = D + (-nb).Qa
并恢复M
希望这有帮助。