下面的vb代码在java中的确切代码是什么,因为我没有得到相同的加密值

下面的vb代码在java中的确切代码是什么,因为我没有得到相同的加密值,java,Java,'使用三重DES加密字符串 私有函数TripleDESEncryptByVal str作为字符串作为TripleDESEncryptResult ' 3DES Encryption ' Generate KEY/IV pair for your local 3DES encrpytion on xmlCard ' Create a new 3DES CryptoProvider and generate KEY/IV pair for encryption Di

'使用三重DES加密字符串 私有函数TripleDESEncryptByVal str作为字符串作为TripleDESEncryptResult

    ' 3DES Encryption
    ' Generate KEY/IV pair for your local 3DES encrpytion on xmlCard

    ' Create a new 3DES CryptoProvider and generate KEY/IV pair for encryption
    Dim m_cryptoProvider As New TripleDESCryptoServiceProvider
    m_cryptoProvider.GenerateIV() 
    m_cryptoProvider.GenerateKey() 

    Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
    Dim cryptoStream As CryptoStream = _
      New CryptoStream(stream, m_cryptoProvider.CreateEncryptor, _
                          CryptoStreamMode.Write)

    Dim Input() As Byte = System.Text.Encoding.Default.GetBytes(str)

    cryptoStream.Write(Input, 0, Input.Length)
    cryptoStream.FlushFinalBlock()

    ' Convert to base64, so it'll be XML-friendly
    Dim encryptedCardString = System.Convert.ToBase64String(stream.ToArray())

    cryptoStream.Close()
    cryptoStream.Dispose()

    Return New TripleDESEncryptResult(encryptedCardString, m_cryptoProvider.Key, m_cryptoProvider.IV)

End Function

下面的代码是用于3DES加密和解密的java代码。请尝试使用此代码。我希望它能帮助你

   private static final String UNICODE_FORMAT = "UTF8";
            public static final String DESEDE_ENCRYPTION_SCHEME = "DESede"; //"DESede/ECB/NoPadding";
            private KeySpec ks;
            private SecretKeyFactory skf;
            private Cipher cipher;
            byte[] arrayBytes;
            private String myEncryptionKey;
            private String myEncryptionScheme;
            SecretKey key;

            public PasswordEncryption_TrippleDES() throws Exception {
                myEncryptionKey =  "ThisIsSpartaThisIsanilku";
                myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME;
                arrayBytes = myEncryptionKey.getBytes(UNICODE_FORMAT);
                ks = new DESedeKeySpec(arrayBytes);
                skf = SecretKeyFactory.getInstance(myEncryptionScheme);
                cipher = Cipher.getInstance(myEncryptionScheme);
                key = skf.generateSecret(ks);
            }


            public String encrypt(String unencryptedString) {
                String encryptedString = null;
                try {
                    cipher.init(Cipher.ENCRYPT_MODE, key);
                    byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT);
                    byte[] encryptedText = cipher.doFinal(plainText);
                    encryptedString = new String(Base64.encodeBase64(encryptedText));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return encryptedString;
            }


            public String decrypt(String encryptedString) {
                String decryptedText=null;
                try {
                    cipher.init(Cipher.DECRYPT_MODE, key);
                    byte[] encryptedText = Base64.decodeBase64(encryptedString);
                    byte[] plainText = cipher.doFinal(encryptedText);
                    decryptedText= new String(plainText);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return decryptedText;
            }
 public static void main(String args []) throws Exception
        {
            PasswordEncryption_TrippleDES td= new PasswordEncryption_TrippleDES();

            String target="data for encyption";
            String encrypted=td.encrypt(target);
            String decrypted=td.decrypt(encrypted);

            System.out.println("String To Encrypt: "+ target);
            System.out.println("Encrypted String:" + encrypted);
            System.out.println("Decrypted String:" + decrypted);

        }

无法识别GenerateKey和GenerateIV方法背后的逻辑您的问题是什么?如何将上述vb.net代码转换为java/到目前为止您是否尝试过任何操作?是的,我尝试了大量代码,但没有得到与vb.net相同的确切加密值。我尝试了您的代码Anil Reddy,但仍然没有得到相同的加密值。但是谢谢你的帮助..你有任何异常吗?没有成功执行它,但加密值与vb.net代码不同。我只需要编写代码,其中加密值应与vb.net代码加密值相同。加密值取决于你在vb.net代码中使用的密钥。在此代码中使用相同的密钥和相同的数据。您将获得相同的加密值