Java密码学结构设计遵循两个原则:
1) 算法的独立性和可靠性。
2) 实现的独立性和相互作用性。
算法的独立性是通过定义密码服务类来获得。用户只需了解密码算法的概念,而不用去关心如何实现这些概念。实现的独立性和相互作用性通过密码服务提供器来实现。密码服务提供器是实现一个或多个密码服务的一个或多个程序包。软件开发商根据一定接口,将各种算法实现后,打包成一个提供器,用户可以安装不同的提供器。安装和配置提供器,可将包含提供器的ZIP和JAR文件放在CLASSPATH下,再编辑Java安全属性文件来设置定义一个提供器。
DES算法及如何利用DES算法加密和解密类文件的步骤:
DES算法简介
DES(Data Encryption Standard)是发明最早的最广泛使用的分组对称加密算法。DES算法的入口参数有三个:Key、Data、Mode。其中Key为8个字节共64位,是DES算法的工作密钥;Data也为8个字节64位,是要被加密或被解密的数据;Mode为DES的工作方式,有两种:加密或解密。
DES加密算法的C语言实现,实在很长
>
''' <summary>
''' 二进制文件流加密类
''' </summary>
''' <remarks></remarks>
Public Class EncryptionDES
''' <summary>
''' 默认密钥向量
''' </summary>
''' <remarks></remarks>
Private Shared Keys As Byte() = New Byte() {&H12, &H34, &H56, 120, &H90, &HAB, &HCD, &HEF}
''' <summary>
''' 文件加密
''' </summary>
''' <param name="encryptBy">待加密文件流</param>
''' <param name="encryptKey">密钥</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function EncryptDES(ByVal encryptBy As Byte(), ByVal encryptKey As String) As Byte()
Dim mStream As MemoryStream = Nothing
Dim cStream As CryptoStream = Nothing
Try
Dim rgbKey As Byte() = EncodingUTF8GetBytes(encryptKeySubstring(0, 8))
Dim rgbIV As Byte() = Keys
Dim dCSP As New DESCryptoServiceProvider
mStream = New MemoryStream
cStream = New CryptoStream(mStream, dCSPCreateEncryptor(rgbKey, rgbIV), CryptoStreamModeWrite)
cStreamWrite(encryptBy, 0, encryptByLength)
cStreamFlushFinalBlock()
Return mStreamToArray
Catch
Return encryptBy
Finally
mStreamDispose()
mStreamClose()
cStreamFlush()
cStreamDispose()
cStreamClose()
End Try
End Function
''' <summary>
''' 文件解密
''' </summary>
''' <param name="decryptBy">待解密文件流</param>
''' <param name="decryptKey">密钥</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function DecryptDES(ByVal decryptBy As Byte(), ByVal decryptKey As String) As Byte()
Dim mStream As MemoryStream = Nothing
Dim cStream As CryptoStream = Nothing
Try
Dim rgbKey As Byte() = EncodingUTF8GetBytes(decryptKey)
Dim rgbIV As Byte() = Keys
Dim DCSP As New DESCryptoServiceProvider
mStream = New MemoryStream
cStream = New CryptoStream(mStream, DCSPCreateDecryptor(rgbKey, rgbIV), CryptoStreamModeWrite)
cStreamWrite(decryptBy, 0, decryptByLength)
cStreamFlushFinalBlock()
Return mStreamToArray
Catch
Return decryptBy
Finally
mStreamDispose()
mStreamClose()
cStreamFlush()
cStreamDispose()
cStreamClose()
End Try
End Function
End Class
Private Sub Button1_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button1Click
Dim by As Byte()
Dim sfd As New SaveFileDialog
sfdInitialDirectory = EnvironmentGetFolderPath(EnvironmentSpecialFolderMyComputer)
sfdFilter = "test(test)|testa"
If sfdShowDialog = DialogResultOK Then
Dim stream As Stream = FileOpen(sfdFileName, FileModeCreate)
Dim formatter As New BinaryFormatter()
formatterSerialize(stream, tClass)
streamClose()
by = FileReadAllBytes(sfdFileName)
FileWriteAllBytes(sfdFileName, EncryptionDESEncryptDES(by, "05320532"))
End If
End Sub
以上就是关于求高手给出以下JAVA代码的DES加密解密方法的对应的C#的DES加密解密方法全部的内容,包括:求高手给出以下JAVA代码的DES加密解密方法的对应的C#的DES加密解密方法、C语言实现DES算法,看清楚进!加分、C#的DES加密解密模块加密解密16进制文本的代码或例子等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)