加密和解密输入数据以创建16到24位字母数字字符串 [英] Encrypt and decrypt input data to create a 16 to 24 digit alphanumeric string

查看:341
本文介绍了加密和解密输入数据以创建16到24位字母数字字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将整个输入数据加密成16到24个字符的字母数字字符串,并再次能够将其解密为c#中的普通字符串?



我尝试过:



有没有办法将整个输入数据加密成16到24个字符的字母数字字符串和再次能够将其解密为c#中的普通字符串?

解决方案

否。



您根本无法将数据加密成固定大小,特别是不能加载到少量位:如果可以的话,我们为什么要将电影流式传输为10GB块,网页作为文本的巨大块?我们只是将它们加密到24个char alpha值并发送它。为什么我们将文件存储在HDD的原始输入而不是存储24个char值并在需要时扩展它?想想节省成本!



恰恰相反:加密数据通常比未加密的数据大得多!



您可能正在考虑生成固定长度输出的MD5和SHA算法 - 但这些算法不是加密算法,它们是散列算法,输出无法转换回来恢复原始输入数据(也就是说设计)。


引用:

有没有办法将整个输入数据加密为16到24字符数字字符串并再次能够将其解密为c#中的普通字符串?



是的,仅当输入不超过24个字符的字母数字字符串时。

注意,使用utf-8,一些字符编码超过8位字符。

如果你的问题意味着将输入的大小改为少于24个字符,那么它就是压缩。没有什么可以保证给定的输出大小。



基本上,加密不会改变输入的大小,或者使用bloc cypher使其更大,因为输入扩展到多个大块大小。


一些评论:

  • 加密不是压缩。如果您正在寻找减少数据大小的方法,那么您应该搜索压缩算法。
  • 通常是加密算法(例如 AES 你标记您的问题)生成二进制数据。您可以通过 base64 ASCII 字符表示此类二进制输出[ ^ ]如果您愿意(这会增加输出大小)。

Is there any way to encrypt the whole Input data into 16 to 24 character alphanumeric string and again able to decrypt it into normal string in c#?

What I have tried:

Is there any way to encrypt the whole Input data into 16 to 24 character alphanumeric string and again able to decrypt it into normal string in c#?

解决方案

No.

You can't encrypt data into a fixed size at all, and particularly not into a small number of bits: if you could, why would we stream movies as 10GB lumps, web pages as huge chunks of "text"? We'd just encrypt them to 24 char alpha values and send that instead. Why would we store files on HDD's in "raw input" instead of storing the 24 char value and expanding it when we needed it? Think of the cost savings!

Rather the opposite: encrypted data is very often significantly larger than the unencrypted source!

You are probably thinking of MD5 and SHA algorithms which do generate fixed length outputs - but those are not encryption algorithms, they are hashing algorithms, and the output cannot be converted back to restore the original input data (and that is by design).


Quote:

Is there any way to encrypt the whole Input data into 16 to 24 character alphanumeric string and again able to decrypt it into normal string in c#?


Yes, only if input is no more than 24 characters alphanumeric string.
Beware, with utf-8, some characters are encoded on more than an 8 bits char.
If your question imply changing the size of input to less than 24 chars, it is compression. And nothing can guaranty a given output size.

Basically, encryption does not change the size of input, or makes it bigger with bloc cypher, because input is expanded to multiple of bloc size.


Some remarks:
  • Encryption is not compression. If you are looking for way to reduce the size of your data, then you should search for compression algorithms.
  • Usually encryption algorithms (e.g. the AES you tagged your question with ) produce binary data. You may represent such binary output with ASCII characters by means of base64[^] if you wish (this would increase the output size).


这篇关于加密和解密输入数据以创建16到24位字母数字字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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