Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2006
    Messaggi
    4

    Cifrare in vb.net Decifrare in Java con DES

    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.Transfo rmFinalBlock(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.get Bytes()));
    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.get Bytes()));

    Dove Sbaglio ????

    Grazie a tutti quello che proveranno a dare una mano !

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2006
    Messaggi
    4

    ... Ancora nei guai ...

    Ho provato di tutto ma non c'è verso

    Il guaio è che non capisco dove sta l'errore....

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.