Convert java code to c #

0

Good morning.

I have had a desktop application in java to convert it to WPF (c #). I do not know much about java but intuiting what it does, little by little I have managed to translate it except for a block of code. The code is as follows:

string key = "CLAVEPARACONVERSION";
string base64EncryptedString = "";
string text = "Esta es la cadena de texto que se va a codificar";

MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digestOfPassword = md.digest(key.getBytes("utf-8"));
byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);

SecretKey key = new SecretKeySpec(keyBytes, "DESede");
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, key);

byte[] plainTextBytes = text.getBytes("utf-8");
byte[] buf = cipher.doFinal(plainTextBytes);
byte[] base64Bytes = Base64.encodeBase64(buf);
base64EncryptedString = new String(base64Bytes);

Can someone help me out? I would appreciate it very much. Greetings and thanks in advance.

    
asked by Alejandro 24.08.2017 в 17:22
source

1 answer

0

The code that appears there is a function of encryption and decryption, to use it in .NET you must use the library System.Security.Cryptography

In this link you will find an example for the algorithm 3DES (DESede) that is in the java code (page in English)

link

See also the description of the MSDN encryption and decryption method:

link

If this serves as an answer, please mark it

    
answered by 26.08.2017 / 00:19
source