开发者

how to resize string [ group of numbers and char]?

Good Afternoon all, I am working over rsa encryption and decryption, for more security i am also using padding in cipher text, for different input (amit) , i am getting different length output like-

plain text- amit     
cipher text-10001123A234A987A765A

My problem is- For big plain tex开发者_Go百科t ,my algo generate large size cipher text, and i thought,

it is wastage of resources to keep long string in database ,

Is there any way with the help of that i can compact cipher and convert real cipher when i will require?


In order for the algorithm to be encryption and not just hashing, it must be reversible. To be reversible, the output must contain as much information as the input, and so is unlikely to be significantly shorter.

You may compress the data before encryption. There's not a lot else you can do unless you're willing to give up the ability to recover your original text from the ciphertext.


There are a couple of possibilities:

  1. Change your encryption scheme there are schemes where the size is same as the input size
  2. Compress your data before you encrypt, this will be effective only if you have a large block of text to encrypt and then there's the additional overhead of decrypting too.


This doesn't apply to RSA specifically, but: any secure cipher will give output close to indistinguishable from a random bit pattern. A random bit pattern has, per definition, maximum information theoretic entropy, since for each bit, both 0 and 1 are equally likely.

Now, you want a lossless compression scheme, since you need to be able to decompress to the exact data you originally compressed. An optimal compression scheme will maximize the entropy of it's output. However, we know that the output of our cipher already has maximum entropy, so we can't possibly increase the entropy.

And thus, trying to compress encrypted data is useless.

Note: Depending on your encryption method, compression might be possible, for example, when using a block cipher in EBC mode. RSA is a completely different beast altogether though, and, well, compressing won't do anything (except quite possibly make your final output bigger).

[Edit] Also, the length of your RSA ciphertext will be in the order of log n. With n your public modulus. This is the reason that, especially for small plaintexts, public key crypto is extremely 'wasteful'. You normally employ RSA to setup a (smaller, e.g. 128-bit) symmetric key between two parties and then encrypt your data with a symmetric key algorithm such as AES. AES has a block size of 128 bits, so if you do straightforward encryption of your data, the maximum 'overhead' you incur will be length(message) mod 128 bits.


erm ... you wrote in a comment here that you apply RSA encryption to all single characters:

i am using rsa- it perform over numbers to convert amit in cipher text first i do a->97 m->109 i->105..and then apply rsa over 97 ,109 ... then i get different integers for 109, 105 or ... i joined that all as a string...

a good advice: don't do that since you will lose the security of RSA

if you use RSA in this way, your scheme becomes a substitution-cypher (with only one substitution alphabet) ... given a reasonably long cypher-text or a reasonable number of cypher-texts, this scheme can be broken by analyzing the frequency of cypher-text-chars

see RSAES-OAEP for a padding scheme to apply to your plaintext before encryption

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜