Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. Visual Studio 6.0
[Vb.Net][Java] Cifrare in vb.net Decifrare in Java con DES
giovedì 25 giugno 2009 - 10.15
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
Un0
Profilo
| Newbie
1
messaggi | Data Invio:
gio 25 giu 2009 - 10:15
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 !
Torna su
Stanze Forum
Elenco Threads
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 !