Equivalent to DESCryptoServiceProvider in Java [closed]

0

In C # I use the following object:

DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();

Is there an equivalent in Java?

    
asked by albetro cota 01.06.2016 в 20:26
source

1 answer

2

Hello, I do not understand what you want with it, I imagine that doing a symmetric encryption, for the case of java, has the api Crypto. I leave the official documentation for you to give you a greater context,

Crypto

String llaveSimetrica = "key";

SecretKeySpec key = new SecretKeySpec(llaveSimetrica.getBytes(), "AES");
      Cipher cipher;
      try {
       cipher = Cipher.getInstance("AES");
    ....{

This is my method in c #

public static string Encrypt(string strText){
        string base64String;

       byte[] numArray = new byte[] { 18, 52, 86, 120, 144, 171, 205, 239 };
        try
        {
            byte[] bytes = Encoding.UTF8.GetBytes("%#@?,:*&");
            byte[] bytes1 = Encoding.UTF8.GetBytes(strText);
            DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
            MemoryStream memoryStream = new MemoryStream();
            CryptoStream cryptoStream = new CryptoStream(memoryStream, dESCryptoServiceProvider.CreateEncryptor(bytes, numArray), CryptoStreamMode.Write);
            cryptoStream.Write(bytes1, 0, (int)bytes1.Length);
            cryptoStream.FlushFinalBlock();
            base64String = Convert.ToBase64String(memoryStream.ToArray());
        }
        catch{base64String = "";}
        return base64String;
    }
    
answered by 01.06.2016 в 20:33