如何加密字符串并获得等长的加密字符串? [英] How do I encrypt a string and get a equal length encrypted string?

查看:197
本文介绍了如何加密字符串并获得等长的加密字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题如下:

在现有数据库中,我想加密几列的数据。
列包含不同长度的字符串。

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

我不想更改列的大小,因此加密需要产生相等长度的文本表示的输入文本。

I don't want to change the size of the columns so the encryption need to produce an equal length text representation of the input text.

加密算法的优点是次要兴趣,但当然我希望它的强度可以是一样的。否则我不需要加密数据。但最重要的是输出的大小。

The strength of the encryption algorithm is of secondary interest but of course I want it to be as strong as it can be. Otherwise I wouldn't need to encrypt the data. But the most important thing is the size of the output.

这可能吗?
如果是这样我该怎么办?

Is this possible? If so how would I do it?

我有兴趣在.NET中执行此操作。没有数据库级加密。

I'm interested in doing it in .NET. No database-level encryption.

推荐答案

在你的警告中,我将使用AES在 CFB 模式,将其转换为流密码,输出长度将与输入长度相同。除非您将字符串存储在blob中,否则需要对输出进行十六进制或base64编码以使其变为友好的,这将长度增加100%或33%。

Within your constrants, I would use AES in CFB mode, which turns it into a stream cipher and the output length will be the same as the input length. Unless you're storing the strings in blobs, you'll need to hex or base64 encode the output to make it char friendly, which will be a 100% or 33% increase in length.

一个.NET实现在这里。

这篇关于如何加密字符串并获得等长的加密字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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