下载

1下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 3DES算法把磁盘d加密

3DES算法把磁盘d加密.doc

3DES算法把磁盘d加密

星辰
2018-09-08 0人阅读 举报 0 0 暂无简介

简介:本文档为《3DES算法把磁盘d加密doc》,可适用于工程科技领域

把磁盘d加密还是加密对D盘的访问,即访问的时候输入密码如果把d盘所有文件加密,那可是一个非常麻烦的事情,对上G的数据进行对称加密还真不知道有什么算法可以高效又安全如果对对称加密感兴趣可以参照下面的加密类usingSystemTextusingSystemusingSystemSecurityCryptographyusingSystemIOpublicclassCryptUtil{publicstaticstringDecryptString(stringinput){if(inputEquals(stringEmpty)){returninput}bytebyKey={x,x,x,xE,x,x,x,xE}byteIV={xFE,xDC,xBA,x,x,x,x,x}byteinputByteArray=newByteinputLengthDESCryptoServiceProviderdes=newDESCryptoServiceProvider()inputByteArray=ConvertFromBaseString(input)MemoryStreamms=newMemoryStream()CryptoStreamcs=newCryptoStream(ms,desCreateDecryptor(byKey,IV),CryptoStreamModeWrite)csWrite(inputByteArray,,inputByteArrayLength)csFlushFinalBlock()Encodingencoding=newEncoding()returnencodingGetString(msToArray())}publicstaticstringEncryptString(stringinput){if(inputEquals(stringEmpty)){returninput}bytebyKey={x,x,x,xE,x,x,x,xE}byteIV={xFE,xDC,xBA,x,x,x,x,x}DESCryptoServiceProviderdes=newDESCryptoServiceProvider()byteinputByteArray=EncodingGetBytes(input)MemoryStreamms=newMemoryStream()CryptoStreamcs=newCryptoStream(ms,desCreateEncryptor(byKey,IV),CryptoStreamModeWrite)csWrite(inputByteArray,,inputByteArrayLength)csFlushFinalBlock()returnConvertToBaseString(msToArray())}<summary>DESBase加密<summary><paramname="input">明文字符串<param><returns>已加密字符串<returns>publicstaticstringDesBaseEncrypt(stringinput){SystemSecurityCryptographyDESdes=SystemSecurityCryptographyDESCreate()desMode=SystemSecurityCryptographyCipherModeECBICryptoTransformctMemoryStreammsCryptoStreamcsbytebytbyteKey=newbyte{,,,,,,,}byteIV=newbyte{,,,,,,,}ct=desCreateEncryptor(Key,IV)byt=EncodingGetEncoding("GB")GetBytes(input)根据GB编码对字符串处理转换成byte数组ms=newMemoryStream()cs=newCryptoStream(ms,ct,CryptoStreamModeWrite)csWrite(byt,,bytLength)csFlushFinalBlock()csClose()byteanswer=msToArray()for(intj=j<answerLengthj){ConsoleWrite(answerjToString()"")}ConsoleWriteLine()returnConvertToBaseString(msToArray())将加密的byte数组依照Base编码转换成字符串}<summary>DESBase解密<summary><paramname="input">密文字符串<param><returns>解密字符串<returns>publicstaticstringDesBaseDecrypt(stringinput){SystemSecurityCryptographyDESdes=SystemSecurityCryptographyDESCreate()desMode=SystemSecurityCryptographyCipherModeECBICryptoTransformctMemoryStreammsCryptoStreamcsbytebytbyteKey=newbyte{,,,,,,,}byteIV=newbyte{,,,,,,,}ct=desCreateDecryptor(Key,IV)byt=ConvertFromBaseString(input)将密文以Base编码转换成byte数组ms=newMemoryStream()cs=newCryptoStream(ms,ct,CryptoStreamModeWrite)csWrite(byt,,bytLength)csFlushFinalBlock()csClose()returnEncodingGetEncoding("GB")GetString(msToArray())将明文以GB编码转换成字符串}<summary>DESBase加密<summary><paramname="input">明文字符串<param><returns>已加密字符串<returns>publicstaticstringDesBaseEncryptForID(stringinput){SystemSecurityCryptographyDESdes=SystemSecurityCryptographyDESCreate()desMode=SystemSecurityCryptographyCipherModeCBCICryptoTransformctMemoryStreammsCryptoStreamcsbytebytbyteKey=newbyte{,,,,,,,}byteIV=newbyte{,,,,,,,}ct=desCreateEncryptor(Key,IV)byt=EncodingGetEncoding("GB")GetBytes(input)根据GB编码对字符串处理转换成byte数组ms=newMemoryStream()cs=newCryptoStream(ms,ct,CryptoStreamModeWrite)csWrite(byt,,bytLength)csFlushFinalBlock()csClose()byteanswer=msToArray()for(intj=j<answerLengthj){ConsoleWrite(answerjToString()"")}ConsoleWriteLine()returnConvertToBaseString(msToArray())将加密的byte数组依照Base编码转换成字符串}<summary>DESBase解密<summary><paramname="input">密文字符串<param><returns>解密字符串<returns>publicstaticstringDesBaseDecryptForID(stringinput){SystemSecurityCryptographyDESdes=SystemSecurityCryptographyDESCreate()desMode=SystemSecurityCryptographyCipherModeCBCICryptoTransformctMemoryStreammsCryptoStreamcsbytebytbyteKey=newbyte{,,,,,,,}byteIV=newbyte{,,,,,,,}ct=desCreateDecryptor(Key,IV)byt=ConvertFromBaseString(input)将密文以Base编码转换成byte数组ms=newMemoryStream()cs=newCryptoStream(ms,ct,CryptoStreamModeWrite)csWrite(byt,,bytLength)csFlushFinalBlock()csClose()returnEncodingGetEncoding("GB")GetString(msToArray())将明文以GB编码转换成字符串}<summary>DES加密BytetoHEXstring<summary><paramname="input">明文字符串<param><returns>已加密字符串<returns>publicstaticstringThreeDesEncryptHEX(stringinput){stringresult=""SystemSecurityCryptographyTripleDESdes=SystemSecurityCryptographyTripleDESCreate()desMode=SystemSecurityCryptographyCipherModeCBCdesPadding=SystemSecurityCryptographyPaddingModePKCSICryptoTransformctMemoryStreammsCryptoStreamcsbytebytbyteKey=newbyte{,,,,,,,,,,,,,,,,,,,,,,,}byteIV=newbyte{,,,,,,,}ct=desCreateEncryptor(Key,IV)byt=EncodingGetEncoding("GB")GetBytes(input)根据GB编码对字符串处理转换成byte数组ms=newMemoryStream()cs=newCryptoStream(ms,ct,CryptoStreamModeWrite)csWrite(byt,,bytLength)csFlushFinalBlock()csClose()byteanswer=msToArray()for(intj=j<answerLengthj){result=answerjToString("x")PadLeft(,'')}returnresult}<summary>DESHEXtobyte解密<summary><paramname="input">密文字符串<param><returns>解密字符串<returns>publicstaticstringThreeDesDecryptHEX(stringinput){SystemSecurityCryptographyTripleDESdes=SystemSecurityCryptographyTripleDESCreate()desMode=SystemSecurityCryptographyCipherModeCBCdesPadding=SystemSecurityCryptographyPaddingModePKCSICryptoTransformctMemoryStreammsCryptoStreamcsbyteKey=newbyte{,,,,,,,,,,,,,,,,,,,,,,,}byteIV=newbyte{,,,,,,,}ct=desCreateDecryptor(Key,IV)byt=ConvertFromBaseString(input)将密文以HEXtobyte编码转换成byte数组if(inputLength<=){thrownewException("encryptedHEXstringistooshort!")}bytebyt=newbyteinputLengthfor(inti=i<bytLengthi){ConsoleWriteLine(inputSubstring(i*,))byti=ConvertToByte(inputSubstring(i*,),)}ms=newMemoryStream()cs=newCryptoStream(ms,ct,CryptoStreamModeWrite)csWrite(byt,,bytLength)csFlushFinalBlock()csClose()returnEncodingGetEncoding("GB")GetString(msToArray())将明文以GB编码转换成字符串}<summary>Base解码<summary><paramname="baseStr"><param><returns><returns>publicstaticstringDecodingFromBase(stringbaseStr){Bytebytes=ConvertFromBaseString(baseStr)returnSystemTextEncodingGetString(bytes)}<summary>Base编码<summary><paramname="str"><param><returns><returns>publicstaticstringEncodingToBase(stringstr){returnConvertToBaseString(EncodingGetBytes(str))}<summary>根据指定的编码方式Base解码<summary><paramname="baseStr"><param><paramname="strEncoding"><param><returns><returns>publicstaticstringDecodingFromBase(stringbaseStr,SystemTextEncodingstrEncoding){Bytebytes=ConvertFromBaseString(baseStr)returnstrEncodingGetString(bytes)}<summary>根据指定的编码方式Base编码<summary><paramname="str"><param><paramname="strEncoding"><param><returns><returns>publicstaticstringEncodingToBase(stringstr,SystemTextEncodingstrEncoding){returnConvertToBaseString(strEncodingGetBytes(str))}}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/7

3DES算法把磁盘d加密

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利