Java encryption:
Package Webdomain;import Java.security.Key; Import Java.security.spec.AlgorithmParameterSpec; Import Javax.crypto.cipher;import javax.crypto.SecretKeyFactory; Import Javax.crypto.spec.deskeyspec;import javax.crypto.spec.ivparameterspec;import Decoder.BASE64Encoder; Public classCrytotools {Private StaticFinalbyte[] Deskey ="here 8-bit key--a". GetBytes ();// Private StaticFinalbyte[] Desiv ="here is another 8-bit key--b". GetBytes ();// StaticAlgorithmparameterspec IV =NULL; Private StaticKey key =NULL; PublicCrytotools () throws Exception {Deskeyspec KeySpec=NewDeskeyspec (Deskey); IV=NewIvparameterspec (DESIV); Secretkeyfactory keyfactory= Secretkeyfactory.getinstance ("DES"); Key=Keyfactory.generatesecret (KEYSPEC); } Publicstring Encode (string data) throws exception{Cipher Encipher= Cipher.getinstance ("des/cbc/pkcs5padding"); Encipher.init (Cipher.encrypt_mode, KEY,IV); byte[] Pasbyte = Encipher.dofinal (Data.getbytes ("Utf-8")); Base64encoder Base64encoder=NewBase64encoder (); returnBase64encoder.encode (Pasbyte); }}
C # decryption
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingsystem.web;usingSystem.Text;usingSystem.Configuration;usingSystem.Security.Cryptography;usingSystem.IO;namespaceappservice{ Public classDES {//des -in-the-sign Public Static stringDesdecode (stringEncryptedstring,stringSKey) { Try { byte[] BtKey = Encoding.Default.GetBytes ("here 8-bit key--a");//キー byte[] Btiv = Encoding.Default.GetBytes ("here another 8-bit key--b");//キーDESCryptoServiceProvider des =NewDESCryptoServiceProvider (); using(MemoryStream ms =NewMemoryStream ()) { byte[] InData =convert.frombase64string (encryptedstring); Try { using(CryptoStream cs =NewCryptoStream (MS, Des. CreateDecryptor (BtKey, Btiv), CryptoStreamMode.Write)) {cs. Write (InData,0, indata.length); Cs. FlushFinalBlock (); } returnEncoding.UTF8.GetString (Ms. ToArray ()); } Catch { returnencryptedstring; } } } Catch { returnencryptedstring; } } }}
"Plus decrypt" Java encryption code and C # decryption code for DES encryption algorithm