对称算法使用一个密钥。给定一个明文和一个密钥,加密产生密文,其长度和明文大致相同。解密时,使用的密钥与加密密钥相同。
对称算法主要有四种加密模式:
一 电子密码本模式 Electronic Code Book(ECB)
这种模式是最早采用和最简单的模式,它将加密的数据分成若干组,每组的大小跟加密密钥长度相同,然后每组都用相同的密钥进行加密。
其缺点是:电子密码本模式用一个密钥加密消息的所有块,如果原消息中重复明文块,则加密消息中的相应密文块也会重复,因此,电子密码本模式适于加密小消息。
二 加密块链模式 Cipher Block Chaining(CBC)
CBC模式的加密首先也是将明文分成固定长度的块,然后将前面一个加密块输出的密文与下一个要加密的明文块进行异或操作,将计算结果再用密钥进行加密得到密文。第一明文块加密的时候,因为前面没有加密的密文,所以需要一个初始化向量。跟ECB方式不一样,通过连接关系,使得密文跟明文不再是一一对应的关系,破解起来更困难,而且克服了只要简单调换密文块可能达到目的的攻击。
三 加密反馈模式 Cipher Feedback Mode(CFB)
面向字符的应用程序的加密要使用流加密法,可以使用加密反馈模式。在此模式下,数据用更小的单元加密,如可以是8位,这个长度小于定义的块长(通常是64位)。其加密步骤是:
1、使用length位的初始化向量。初始化向量放在移位寄存器中,在第一步加密,产生相应的length位初始化密文K;
2、初始化密文K高n位与明文前n位进行异或运算,产生密文第一部分c(密文块0),然后将c传输到接收方;
3、向量的位(即初始化向量所在的移位寄存器内容)左移n位,使移位寄存器最右边的n位为不可预测的数据,在其中填入c的内容;
4、重复第1-3步,直到加密所有的明文单元。
解密过程相反
四 输出反馈模式 Output Feedback Mode(OFB)
输出反馈模式与CFB相似,惟一差别是,CFB中密文填入加密过程下一阶段,而在OFB中,初始化向量加密过程的输出K的高n位填入加密过程下一阶段。
- 大小: 156.4 KB
- 大小: 73.5 KB
- 大小: 113.6 KB
- 大小: 149.3 KB
<script type="text/javascript"> /*iteye博客内页Banner-468*60,创建于2016-5-31*/ var cpro_id = "u1405021"; </script> <script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/c.js"></script>
分享到:
<script type="text/javascript"> dp.SyntaxHighlighter.HighlightAll('code', true, true); $$('#main .blog_content pre[name=code]').each(function(pre, index){ // blog content var post_id = 2343834; var location = window.location; source_url = location.protocol + "//" + location.host + location.pathname + location.search; pre.writeAttribute('codeable_id', post_id); pre.writeAttribute('codeable_type', "Blog"); pre.writeAttribute('source_url', source_url); pre.writeAttribute('pre_index', index); pre.writeAttribute('title', '对称算法的四种运行模式'); }); fix_image_size($$('div.blog_content img'), 700); function processComment() { $$('#main .blog_comment > div').each(function(comment){// comment var post_id = comment.id.substr(2); $$("#"+comment.id+" pre[name=code]").each(function(pre, index){ var location = window.location; source_url = location.protocol + "//" + location.host + location.pathname + location.search; source_url += "#" + comment.id; pre.writeAttribute('codeable_id', post_id); pre.writeAttribute('codeable_type', "BlogComment"); pre.writeAttribute('source_url', source_url); pre.writeAttribute('pre_index', index); pre.writeAttribute('title', '对称算法的四种运行模式'); }); }); } function quote_comment(id) { new Ajax.Request('/editor/quote', { parameters: {'id':id, 'type':'BlogComment'}, onSuccess:function(response){editor.bbcode_editor.textarea.insertAfterSelection(response.responseText); Element.scrollTo(editor.bbcode_editor.textarea.element);} }); } code_favorites_init(); processComment(); new WeiboShare({share_buttons: $('share_weibo'), img_scope: $('blog_content')}); </script>
- 浏览: 93681 次
- 性别:
- 来自: 西安
评论排行榜