How do I encrypt a string and get a equal length encrypted string?

后端 未结 8 1013
南笙
南笙 2020-12-09 05:55

My problem is the following:

In an existing database I want to encrypt data in a couple of columns. The columns contains strings of different lengths.

I don\

相关标签:
8条回答
  • 2020-12-09 06:24

    Secure encryption requires that the ciphertext be larger than the plaintext; otherwise identical plaintext always results in identical ciphertext, and there's no such thing as an invalid ciphertext, which are both weaknesses.

    However, if you really can't expand the data you're encrypting, the best you can do is a tweakable block mode. Look up XTS and CMC modes which are used for disk encryption.

    0 讨论(0)
  • 2020-12-09 06:26

    The Vigenère cipher can do that. But it is old (pre-computer) and only secure if your key phrase is longer than the longest string you want to encrypt. Plus, having a database full of strings encrypted with the same key phrase will probably make this a week encryption, especially if the plain texts can be guessed.

    It works more or less like the cesar shift algorithm (add n to each letter in plain text), except that n is different for each letter being changed, based on a key phrase.

    If your key phrase is ABCDEFG, then it means n=1 for first letter of input, 2 for second letter of input etc.

    With a random key phrase longer than the plain text, the output is just as random (secure). But I believe this will break down if you have many strings encrypted with the same key. ..

    0 讨论(0)
提交回复
热议问题