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

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

问题描述

我的问题是这样的:

在我想在一列中的数据进行加密现有数据库。 列包含不同长度的串

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

我不想更改列的大小,以便加密需要产生输入文本的长度相等的文本再presentation。

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.

推荐答案

在你的constrants,我会用AES中的 CFB 的模式,从而把它变成一个流密码和输出长度将是相同的作为输入的长度。除非你存储在斑点的字符串,则需要十六进制或Base64 EN code的输出,使其烧焦友好的,这将是在长度上增加了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天全站免登陆