由于上述代码未解决的错误,因为我认为此flexiprovider与jdk-8不兼容,其中的错误位于“ KeyFactory kf =
KeyFactory.getInstance(“ ECIES”,“FlexiEC”)“行中,该行找不到我将其命名为曲线,然后更改并决定使用BouncyCastle提供程序进行EC加密(ECIES),并且它可以正常工作。但是我再次想到一个问题,就像我在使用的Flexiprovider中所看到的那样
(“ AES128_CBC”,“ HmacSHA1”,null,null); 作为 IESParameterSpec 。但是对于
充气城堡 提供者,我找不到 IESParameterSpec 在 哪里
哪个使用AES128_CBC作为iesparameterspec,如果要在使用此弹性提供程序时将iesparam更改为AES128_CBC,该怎么办?有人请在弹性提供程序中解释有关此iesparam规范,我对此并不陌生。
这是我的信息代码:
- 密钥对生成器类
import prec.base64; // or whatever which can use to base64 encoding import static java.lang.System.out; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.PublicKey; import java.security.Security; import java.security.spec.ECGenParameterSpec; import java.security.spec.PKCS8EnpredKeySpec; import java.security.spec.X509EnpredKeySpec; import javax.crypto.Cipher; import org.bouncycastle.jce.provider.BouncyCastleProvider; ... Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECIES", "BC"); ECGenParameterSpec brainpoolP160R1 = new ECGenParameterSpec("brainpoolP160R1"); // I'm Still using this 160 bit GF(*p*) to keep the algorithm running fast rather than 256 or above kpg.initialize(brainpoolP160R1); KeyPair kp = kpg.generateKeyPair(); PublicKey publicKey = kp.getPublic(); PrivateKey privateKey = kp.getPrivate(); byte[] PublicKey = publicKey.getEnpred(); byte[] PrivateKey = privateKey.getEnpred(); out.println("Enpred Public : "+base64.enpre(PublicKey)); out.println("nEnpred Private : "+base64.enpre(PrivateKey)); ...- 加密类(发送方)
import prec.base64; import prec.CorruptedCodeException; import java.security.InvalidKeyException; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.PublicKey; import java.security.Security; import java.security.spec.InvalidKeySpecException; import java.security.spec.X509EnpredKeySpec; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import org.bouncycastle.jce.provider.BouncyCastleProvider; ... Security.addProvider(new BouncyCastleProvider()); // Assume that we know the enpred public key then return it by depre the public key byte[] depredPublic = base64.depre("MEIwFAYHKoZIzj0CAQYJKyQDAwIIAQEBAyoABNXclcmtUt8/rlGN47pc8ZpxkWgNgtKeeHdsVD0kIWLUMEULnchGZPA=".getBytes()); X509EnpredKeySpec formatted_public = new X509EnpredKeySpec(depredPublic); KeyFactory kf = KeyFactory.getInstance("EC","BC"); PublicKey pubKey = kf.generatePublic(formatted_public); Cipher c = Cipher.getInstance("ECIES", "BC"); c.init(Cipher.ENCRYPT_MODE, pubKey); // How can i put the AES128_CBC for ies parameter ? is that possible byte[] cipher = c.doFinal("This is the message".getBytes()); System.out.println("Ciphertext : "+ base64.enpre(cipher)); ...- 解密类(接收方)
import prec.base64; import prec.CorruptedCodeException; import java.security.InvalidKeyException; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.PrivateKey; import java.security.Security; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EnpredKeySpec; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import org.bouncycastle.jce.provider.BouncyCastleProvider; ... Security.addProvider(new BouncyCastleProvider()); // Assume that we know the enpred private key byte[] depredPrivate = base64.depre("MHECAQAwFAYHKoZIzj0CAQYJKyQDAwIIAQEBBFYwVAIBAQQUQmA9ifs472gNHBc5NSGYq56TlOKgCwYJKyQDAwIIAQEBoSwDKgAE1dyVya1S3z+uUY3julzxmnGRaA2C0p54d2xUPSQhYtQwRQudyEZk8A==".getBytes()); PKCS8EnpredKeySpec formatted_private = new PKCS8EnpredKeySpec(depredPrivate); KeyFactory kf = KeyFactory.getInstance("EC", "BC"); PrivateKey privKey = kf.generatePrivate(formatted_private); Cipher c = Cipher.getInstance("ECIES"); c.init(Cipher.DECRYPT_MODE, privKey); //How can i adding the **AES128_CBC** ies param ? // Assume that we know the enpred cipher text byte[] plaintext = c.doFinal(base64.depre("BKbCsKY7gDPld+F4jauQXvKSayYCt6vOjIGbsyXo5fHWo4Ax+Nt5BQ5FlkAGksFNRQ46agzfxjfuoxWkVfnt4gReDmpPYueUbiRiHp1Gwp0=")); System.out.println("nPlaintext : "+ new String (plaintext)); ...任何帮助将是适当的!



