Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 加密密钥大小和算法_Vb.net - Fatal编程技术网

Vb.net 加密密钥大小和算法

Vb.net 加密密钥大小和算法,vb.net,Vb.net,以下是我拥有的一些完美的代码: Sub EncryptFile(ByVal sInputFilename As String, _ ByVal sOutputFilename As String, _ ByVal sKey As String) Dim fsInput As New FileStream(sInputFilename, _ FileMode.Open,

以下是我拥有的一些完美的代码:

   Sub EncryptFile(ByVal sInputFilename As String, _
              ByVal sOutputFilename As String, _
              ByVal sKey As String)

  Dim fsInput As New FileStream(sInputFilename, _
                              FileMode.Open, FileAccess.Read)
  Dim fsEncrypted As New FileStream(sOutputFilename, _
                              FileMode.Create, FileAccess.Write)

  Dim DES As New DESCryptoServiceProvider()

  'Set secret key for DES algorithm.
  'A 64-bit key and an IV are required for this provider.
  DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey)

  'Set the initialization vector.
  DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)

  'Create the DES encryptor from this instance.
  Dim desencrypt As ICryptoTransform = DES.CreateEncryptor()
  'Create the crypto stream that transforms the file stream by using DES encryption.
  Dim cryptostream As New CryptoStream(fsEncrypted, _
                                      desencrypt, _
                                      CryptoStreamMode.Write)

  'Read the file text to the byte array.
  Dim bytearrayinput(fsInput.Length - 1) As Byte
  fsInput.Read(bytearrayinput, 0, bytearrayinput.Length)
  'Write out the DES encrypted file.
  cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
  cryptostream.Close()
端接头

是否可以使用此代码更改密钥大小,甚至在MD5和SHA1加密之间进行选择?如果没有,有人能给我指出正确的方向,让我找到正确的方向吗

谢谢


Simon是一种加密算法。如果要使用其他内容,应查看TripleDESCryptoServiceProvider或AesCryptoServiceProvider(在命名空间中)

MD5和SHA1实际上是散列算法。实际上,它们是无法解密的特例单向加密算法(因此我认为它们不是您要寻找的)

只要看一下TripleDES和Aes类的文档,您就应该能够替换以下行:

Dim DES As New DESCryptoServiceProvider()
使用提供CreateEncryptor函数的任何其他CryptoServiceProvider类。它们还支持可以设置的KeySize属性。您可以尝试以下方法:

Sub EncryptFile(ByVal sInputFilename As String, _
          ByVal sOutputFilename As String, _
          ByVal sKey As String, _
          ByVal keysize as integer, _
          ByVal algorithm as String)

  Dim fsInput As New FileStream(sInputFilename, _
                          FileMode.Open, FileAccess.Read)
  Dim fsEncrypted As New FileStream(sOutputFilename, _
                          FileMode.Create, FileAccess.Write)

  Dim algorithm As SymmetricAlgorithm
  Select Case algorithm
      Case "DES": algorithm = New DESCryptoServiceProvider()
      Case "3DES": algorithm = New TripleDESCryptoServiceProvider()
      Case "AES": algorithm = New AESCryptoServiceProvider()
  End Select
  algorithm.KeySize = keysize

  'Set secret key for the algorithm.
  'A 64-bit key and an IV are required for this provider.
  algorithm.Key = ASCIIEncoding.ASCII.GetBytes(sKey)

  'Set the initialization vector.
  algorithm.IV = ASCIIEncoding.ASCII.GetBytes(sKey)

  'Create the encryptor from this instance.
  Dim desencrypt As ICryptoTransform = algorithm.CreateEncryptor()
  'Create the crypto stream that transforms the file stream by using encryption.
  Dim cryptostream As New CryptoStream(fsEncrypted, _
                                  desencrypt, _
                                  CryptoStreamMode.Write)

  'Read the file text to the byte array.
  Dim bytearrayinput(fsInput.Length - 1) As Byte
  fsInput.Read(bytearrayinput, 0, bytearrayinput.Length)
  'Write out the DES encrypted file.
  cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
  cryptostream.Close()
End Sub
我没有尝试编译上面的示例,但我希望您能开始编写