加密算法与数字签名技术解析
1. El Gamal算法
El Gamal是Diffie - Hellman算法的一个变体,其安全性基于相同的原理。尽管在某些方面它不如RSA算法“简洁”,但它仍然被广泛使用,是Open PGP(RFC 2440)中大多数加密密钥的首选算法。
在El Gamal算法中,向公钥为Gy mod P的另一方发送消息时,需要创建一个临时公钥Gx mod P,将消息乘以Gxy mod P进行加密(乘法也进行模P运算),并将临时公钥和加密后的消息作为一个整体发送。不过,这样做会使密文的大小变为密钥的两倍。
1.1 El Gamal加密示例
以下是一个使用El Gamal进行随机密钥生成和加密的示例代码:
package chapter4;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import javax.crypto.Cipher;
/**
* El Gamal example with random key generation.
*/
public class RandomKeyElGamalExample
{
public static void main(String[] args) throws Exception
{
byte[] input = new byte[] { (b
超级会员免费看
订阅专栏 解锁全文
1153

被折叠的 条评论
为什么被折叠?



