[Vb.Net][Java] Cifrare in vb.net Decifrare in Java con DES

giovedì 25 giugno 2009 - 10.15

Un0 Profilo | Newbie

Ciao a tutti, spero di postare nella sezione giusta ...

Veniamo subito al problema: devo cifrare con des una stringa in vb.net e decifrarla con un programma in java, di seguito il codice che utilizzo:

LATO VB.NET (CIFRO)

Public Function desCrypt(ByVal Clear_Text As String) As String
Dim Cipher_text As String = ""
Dim bytIV As Byte() = {12, 89, 148, 62, 0, 78, 254, 129}

Dim algDES As DES = DES.Create
Dim desEncryptor As ICryptoTransform = algDES.CreateEncryptor((StrToByteArray("abcdefgh")), bytIV)
Dim bytInput() As Byte
bytInput = UTF8.GetBytes(Clear_Text)
Cipher_text = System.Convert.ToBase64String(desEncryptor.TransformFinalBlock(bytInput, 0, bytInput.Length))

Return Cipher_text

End Function

LATO JAVA (DECIFRO, O ALMENO CI PROVO)

public String Des_decrypt (String cipher_text)
{



String algorithm = "DES";
String recovered ="";
SecretKey key = null;
Cipher cipher = null;
try
{
KeySpec keySpec = new DESKeySpec("abcdefgh".getBytes());
key = SecretKeyFactory.getInstance("DES").generateSecret(keySpec);

cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] recoveredBytes = cipher.doFinal(Base64.decodeBase64(cipher_text.getBytes()));
recovered = recoveredBytes.toString();

}
catch (Exception e) {

e.printStackTrace();
}
return recovered;
}

Ovviamente il tutto non funziona, il messaggio di errore (quando decifro in java) è :"Input length must be multiple of 8 when decrypting with padded cipher"

La riga che causa l'errore è : byte[] recoveredBytes = cipher.doFinal(Base64.decodeBase64(cipher_text.getBytes()));

Dove Sbaglio ????

Grazie a tutti quelli che proveranno a dare una mano !
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5