[英]ECIES secure mode and padding scheme for ECC Algorithm -Java
ECIES 替換的最佳安全模式和填充方案是什么。
Cipher c = Cipher.getInstance("ECIES");
public static byte[] eccEnc(String msg,String pub) throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, InvalidKeySpecException, NoSuchProviderException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException {
//get the public key from public key text
byte[] enKeyByte = Base64.getDecoder().decode(pub);
KeyFactory kf = KeyFactory.getInstance("EC");
X509EncodedKeySpec keySpecPb = new X509EncodedKeySpec(enKeyByte);
PublicKey publicKey = kf.generatePublic(keySpecPb);
//Impl
byte[] d = new byte[]{1, 2, 3, 4, 5, 6, 7, 8};
byte[] e = new byte[]{8, 7, 6, 5, 4, 3, 2, 1};
IESParameterSpec param = new IESParameterSpec(d, e, 256);
Cipher c = Cipher.getInstance("ECIES");
c.init(Cipher.ENCRYPT_MODE,publicKey, param);
byte[] message = msg.getBytes();
byte[] cipher = c.doFinal(message);
System.out.println(new String(cipher));
return cipher;
}
Cipher.getInstance("ECIES/None/NoPadding", "BC"); 解決的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.