PHP
class JoDES { private static $_instance = NULL; /** * @return JoDES */ public static function share() { if (is_null(self::$_instance)) { self::$_instance = new JoDES(); } return self::$_instance; } /** * 加密 * @param string $str 要处理的字符串 * @param string $key 加密Key,为8个字节长度 * @return string */ public function encode($str, $key) { $size = mcrypt_get_block_size(MCRYPT_DES, MCRYPT_MODE_CBC); $str = $this->pkcs5Pad($str, $size); $aaa = mcrypt_cbc(MCRYPT_DES, $key, $str, MCRYPT_ENCRYPT, $key); $ret = base64_encode($aaa); return $ret; } /** * 解密 * @param string $str 要处理的字符串 * @param string $key 解密Key,为8个字节长度 * @return string */ public function decode($str, $key) { $strBin = base64_decode($str); $str = mcrypt_cbc(MCRYPT_DES, $key, $strBin, MCRYPT_DECRYPT, $key); $str = $this->pkcs5Unpad($str); return $str; } function hex2bin($hexData) { $binData = ""; for ($i = 0; $i < strlen($hexData); $i += 2) { $binData .= chr(hexdec(substr($hexData, $i, 2))); } return $binData; } function pkcs5Pad($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); return $text . str_repeat(chr($pad), $pad); } function pkcs5Unpad($text) { $pad = ord($text {strlen($text) - 1}); if ($pad > strlen($text)) return false; if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false; return substr($text, 0, - 1 * $pad); } }
C#
public class MyDes { /// <summary> /// DES加密方法 /// </summary> /// <param name="strPlain">明文</param> /// <param name="strDESKey">密钥</param> /// <param name="strDESIV">向量</param> /// <returns>密文</returns> public static string Encode(string source, string _DESKey) { StringBuilder sb = new StringBuilder(); using (DESCryptoServiceProvider des = new DESCryptoServiceProvider()) { byte[] key = ASCIIEncoding.ASCII.GetBytes(_DESKey); byte[] iv = ASCIIEncoding.ASCII.GetBytes(_DESKey); byte[] dataByteArray = Encoding.UTF8.GetBytes(source); des.Mode = System.Security.Cryptography.CipherMode.CBC; des.Key = key; des.IV = iv; string encrypt = ""; using (MemoryStream ms = new MemoryStream()) using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(dataByteArray, 0, dataByteArray.Length); cs.FlushFinalBlock(); encrypt = Convert.ToBase64String(ms.ToArray()); } return encrypt; } } /// <summary> /// 进行DES解密。 /// </summary> /// <param name="pToDecrypt">要解密的base64串</param> /// <param name="sKey">密钥,且必须为8位。</param> /// <returns>已解密的字符串。</returns> public static string Decode(string source, string sKey) { byte[] inputByteArray = System.Convert.FromBase64String(source);//Encoding.UTF8.GetBytes(source); using (DESCryptoServiceProvider des = new DESCryptoServiceProvider()) { des.Key = ASCIIEncoding.ASCII.GetBytes(sKey); des.IV = ASCIIEncoding.ASCII.GetBytes(sKey); System.IO.MemoryStream ms = new System.IO.MemoryStream(); using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); cs.Close(); } string str = Encoding.UTF8.GetString(ms.ToArray()); ms.Close(); return str; } } }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.