SoFunction
Updated on 2025-04-13

Java easy to understand and easy to use MD5 encryption (can be run directly) (1) Page 2/2


5. The newline symbol of the string can be removed as needed.
Copy the codeThe code is as follows:

/**
* Remove the newline symbol of the string
* When base64 encodes 3-DES data, the obtained string has line break symbols, which can be removed as needed.
*/
private String filter(String str)
{
String output = null;
StringBuffer sb = new StringBuffer();
for(int i = 0; i < (); i++)
{
int asc = (i);
if(asc != 10 && asc != 13)
((i, i + 1));
}
output = new String(sb);
return output;
}

6. Encoding strings
Copy the codeThe code is as follows:

/**
* Encoding the string (strEncoding)
* @param String src string to encode
*
* @return String Encoded string
*/
public String getURLEncode(String src)
{
String requestValue="";
try{

requestValue = (src);
}
catch(Exception e){
();
}

return requestValue;
}

7. Decode the string (strEncoding)
Copy the codeThe code is as follows:

/**
* Decode the string (strEncoding)
* @param String src string to decode
*
* @return String Decoded string
*/
public String getURLDecoderdecode(String src)
{
String requestValue="";
try{

requestValue = (src);
}
catch(Exception e){
();
}

return requestValue;
}

8. Perform 3-DES decryption (the key is equivalent to the encrypted key)
Copy the codeThe code is as follows:

/**
*
* Perform 3-DES decryption (the key is equivalent to the encrypted key).
* @param byte[] src To perform 3-DES decryption byte[]
* @param String spkey allocated SPKEY
* @return String 3-DES decrypted String
*/
public String deCrypt(byte[] debase64,String spKey)
{
String strDe = null;
Cipher cipher = null;
try
{
cipher=("DESede");
byte[] key = getEnKey(spKey);
DESedeKeySpec dks = new DESedeKeySpec(key);
SecretKeyFactory keyFactory = ("DESede");
SecretKey sKey = (dks);
(Cipher.DECRYPT_MODE, sKey);
byte ciphertext[] = (debase64);
strDe = new String(ciphertext,"UTF-16LE");
}
catch(Exception ex)
{
strDe = "";
();
}
return strDe;
After the above steps, MD5 encryption can be completed, 3-DES encryption, base64 encoding transmission, base64 decoding, and 3-DES decryption can be obtained.
Previous page12Read the full text