为什么我的Elgamal实现不适用于长文本字符串? [英] Why doesn't my implementation of ElGamal work for long text strings?

查看:183
本文介绍了为什么我的Elgamal实现不适用于长文本字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用El Gamal密码系统,我的目标是能够加密和解密长的文本序列。



El Gamal要求明文是一个整数。我已经把我的字符串变成一个byte []使用.getBytes()方法为字符串,然后创建一个BigInteger的byte []。在加密/解密之后,我使用BigIntegers的.toByteArray()方法将BigInteger转换为byte [],然后从byte []创建一个新的String对象。



我使用一个1035位的密钥,当我用最多129个字符的字符串加密/解密时,这是完美的。如果有130个或更多字符,我的解密方法产生的输出是乱码。



有人可以建议如何解决这个问题?

I'm playing with the El Gamal cryptosystem, and my goal is to be able to encipher and decipher long sequences of text.

El Gamal requires the plaintext to be an integer. I have turned my string into a byte[] using the .getBytes() method for Strings, and then created a BigInteger out of the byte[]. After encryption/decryption, I turn the BigInteger into a byte[] using the .toByteArray() method for BigIntegers, and then create a new String object from the byte[].

I am using a 1035 bit key, and this works perfectly when I encipher/decipher with strings up to 129 characters. With 130 or more characters, the output produced from my decipher method is garbled.

Can someone suggest how to solve this issue?

解决方案

Just like in RSA, you cannot encrypt a value larger than the modulus in ElGamal.

这篇关于为什么我的Elgamal实现不适用于长文本字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆