Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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
Java 什么是正确的.Net方法来解密android AES加密文件_Java_Android_Vb.net_Encryption - Fatal编程技术网

Java 什么是正确的.Net方法来解密android AES加密文件

Java 什么是正确的.Net方法来解密android AES加密文件,java,android,vb.net,encryption,Java,Android,Vb.net,Encryption,我使用以下方法在android中加密了一个zip文件: String s_InitKey = "1612211310164660"; String s_IvSpec = "MySecreteBytes00"; IvParameterSpec iv = new IvParameterSpec(s_IvSpec.getBytes("UTF-8")); SecretKeySpec key = new SecretKeySpec(s_InitKey.getBytes("UTF-8"), "AES");

我使用以下方法在android中加密了一个zip文件:

String s_InitKey = "1612211310164660";
String s_IvSpec = "MySecreteBytes00";

IvParameterSpec iv = new IvParameterSpec(s_IvSpec.getBytes("UTF-8"));
SecretKeySpec key = new SecretKeySpec(s_InitKey.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, key, iv);
我需要使用windows解密文件,我尝试了以下方法:

    Private Sub LicenceEncryptOrDecrypt(LizenzDatei As String, EncryptOrDecrypt As String)

        Dim Rijndael As RijndaelManaged = New RijndaelManaged

        Dim passPhrase As String = "SuperPassword"
        Dim hashAlgorithm As String = "SHA1"
        Dim passwordIterations As Integer = 3
        Dim keySize As Integer = 128

        Dim initVector As String = "16charLongString"
        Rijndael.IV = Encoding.ASCII.GetBytes(initVector)

        Dim saltValue As String = "DoYouWantSomeSalt"
        Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)

        Dim password As Rfc2898DeriveBytes = New Rfc2898DeriveBytes(passPhrase, saltValueBytes)

        Rijndael.Key = password.GetBytes(keySize / 8)

        Rijndael.Padding = PaddingMode.None


        Dim transform As ICryptoTransform
        Dim tempFile As String


        Select Case EncryptOrDecrypt
            Case "Encrypt"
                transform = Rijndael.CreateEncryptor(Rijndael.Key, Rijndael.IV)
                tempFile = LizenzDatei + ".enc"
            Case "Decrypt"
                transform = Rijndael.CreateDecryptor(Rijndael.Key, Rijndael.IV)
                tempFile = LizenzDatei + ".dec"
            Case Else
                Debug.Print(">< EncryptOrDecrypt: Falshes parameter. Ende Sub.")
                Success = False
        End Select


        Using inFS As FileStream = New FileStream(LizenzDatei, FileMode.Open)
            Dim data() As Byte = New Byte(inFS.Length - 1) {}

            Using outFS As FileStream = New FileStream(tempFile, FileMode.Create)
                Using outStreamEncrypted As CryptoStream = New CryptoStream(outFS, transform, CryptoStreamMode.Write)
                    outStreamEncrypted.Write(data, 0, data.Length)
                    outStreamEncrypted.FlushFinalBlock()
                    outStreamEncrypted.Close()
                End Using
                outFS.Close()
            End Using
            inFS.Close()
        End Using

        File.Delete(LizenzDatei)
        File.Move(tempFile, LizenzDatei)

    End Sub

除非数据总是块大小的倍数,否则应该使用填充。加密和解密都需要使用相同的填充模式

最好删除测试用例中的非必要代码


如果要验证加密和解密,可以使用Cryptomathic提供的在线AES服务

除非数据总是块大小的倍数,否则应使用填充。加密和解密都需要使用相同的填充模式

最好删除测试用例中的非必要代码


如果要验证加密和解密,可以使用Cryptomathic提供的在线AES服务

一,。为什么要指定
PaddingMode.None
?2.您是否通过十六进制转储验证密钥是否相同?3.我假设事实上iv是一样的。4.你试过用一个小文件,比如说40字节吗?5.对于加密和解密,请以十六进制形式提供密钥iv、输入数据和输出数据。
SecretKeySpec
工作原理的详细信息在哪里?它真的是Rfc2898DeriveBytes吗
hashAlgorithm
passwordIterations
从未使用过。当我在没有
PaddingMode
的情况下运行代码时,我收到的
填充无效且无法删除。
错误。Rfc2898DeriveBytes没有关系,我删除了它,并用一个更简单的键方法重新调整了它的速度,以便进行测试。我还没有测试原始字节加密。我还删除了hashAlgorithm,我将更新代码以显示我的修改。谢谢zaph,我在加密函数中添加了模式和填充,现在它工作得很好。1。为什么要指定
PaddingMode.None
?2.您是否通过十六进制转储验证密钥是否相同?3.我假设事实上iv是一样的。4.你试过用一个小文件,比如说40字节吗?5.对于加密和解密,请以十六进制形式提供密钥iv、输入数据和输出数据。
SecretKeySpec
工作原理的详细信息在哪里?它真的是Rfc2898DeriveBytes吗
hashAlgorithm
passwordIterations
从未使用过。当我在没有
PaddingMode
的情况下运行代码时,我收到的
填充无效且无法删除。
错误。Rfc2898DeriveBytes没有关系,我删除了它,并用一个更简单的键方法重新调整了它的速度,以便进行测试。我还没有测试原始字节加密。我还删除了hashAlgorithm,我将更新代码以显示我的修改。谢谢zaph,我在加密函数中添加了模式和填充,现在它工作得很好。
Private Sub LicenceEncryptOrDecrypt(EncryptedFile As SimpleFile, Direction As CryptoAction)
        Dim Rijndael As RijndaelManaged = New RijndaelManaged

        Dim hashAlgorithm As String = "AES"

        Rijndael.Padding = PaddingMode.None

        Dim s_Temp As String = EncryptedFile.Name.Substring(9, EncryptedFile.Name.Length - 9)
        Dim c_Date As New SimpleDate(s_Temp)
        'c_Date.getKey translates 16bit key'
        Dim Key As Byte() = System.Text.Encoding.UTF8.GetBytes(c_Date.getKey)
        Dim IV As Byte() = System.Text.Encoding.UTF8.GetBytes("MySecreteBytes00")

        Rijndael.IV = IV
        Rijndael.Key = Key


        Dim transform As ICryptoTransform
        Dim tempFile As String


        Select Case Direction
            Case CryptoAction.ActionEncrypt
                transform = Rijndael.CreateEncryptor(Rijndael.Key, Rijndael.IV)
                tempFile = EncryptedFile.FullPath
            Case CryptoAction.ActionDecrypt
                transform = Rijndael.CreateDecryptor(Rijndael.Key, Rijndael.IV)
                tempFile = EncryptedFile.Path + "\" + EncryptedFile.Name + ".zip""
        End Select

        Dim data() As Byte = System.IO.File.ReadAllBytes(EncryptedFile.FullPath)

        Using outFS As FileStream = New FileStream(tempFile, FileMode.Create)
            Using outStreamEncrypted As CryptoStream = New CryptoStream(outFS, transform, CryptoStreamMode.Write)
                outStreamEncrypted.Write(data, 0, data.Length)
                outStreamEncrypted.FlushFinalBlock()
                outStreamEncrypted.Close()
            End Using
            outFS.Close()
        End Using
    End Sub