栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flexiprovider-如何使用格式化的密钥对加密/解密

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flexiprovider-如何使用格式化的密钥对加密/解密

由于上述代码未解决的错误,因为我认为此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));    ...

任何帮助将是适当的!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/438645.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号