Home > Mobile >  Help Java the encrypted data to WeChat small program how to decrypt my own solution after data is wr
Help Java the encrypted data to WeChat small program how to decrypt my own solution after data is wr

Time:12-06

In the Java encryption
//encryption device information
Public String Encrypt (String content, String strKey, String strIV) {//key and iv value with 64 turn content need not 64 turn (pit)
Byte [] bOut=null;
//the string plaintext into utf-8 bytes
Byte [] data=https://bbs.csdn.net/topics/new byte [0];
Try {
Data=https://bbs.csdn.net/topics/content.getBytes (" utf-8 ");
The Key deskey=null;
BASE64Decoder d=new BASE64Decoder ();
Byte [] sKey=d.d ecodeBuffer (strKey);
DESedeKeySpec spec=new DESedeKeySpec (sKey);
SecretKeyFactory keyfactory=SecretKeyFactory. GetInstance (" desede ");
Deskey=keyfactory. GenerateSecret (spec);
Cipher Cipher=Cipher. GetInstance (" desede "+"/CBC/PKCS5Padding ");//PKCS7Padding desede "+"/CBC/ZeroPadding
Byte [] b=d.d ecodeBuffer (strIV);
IvParameterSpec ips=new IvParameterSpec (b);
Cipher. The init (cipher ENCRYPT_MODE, deskey, ips);//ENCRYPT_MODE, data encryption, decryption data DECRYPT_MODE,
BOut=cipher. DoFinal (data);
} the catch (Exception e) {
e.printStackTrace();
}
BASE64Encoder encoder=new BASE64Encoder ();
String STR=encoder. Encode (bOut);
return str;
}

In the Java decryption

//decrypt the data
Public String deCrypt (String content, String strKey, String strIV) {
BASE64Decoder decoder=new BASE64Decoder ();
String s="";
Try {
Byte [] deContent=decoder. DecodeBuffer (content).//content
Byte [] ivByte=decoder. DecodeBuffer (strIV);//iv
Byte [] bytekey=decoder. DecodeBuffer (strKey);//bytekey

DESedeKeySpec spec=new DESedeKeySpec (bytekey);
SecretKeyFactory keyfactory=SecretKeyFactory. GetInstance (" desede ");
The Key deskey=keyfactory. GenerateSecret (spec);//key
Cipher Cipher=Cipher. GetInstance (" desede "+"/CBC/PKCS5Padding ");//PKCS7Padding desede "+"/CBC/ZeroPadding
IvParameterSpec ips=new IvParameterSpec (ivByte);
Cipher. The init (cipher DECRYPT_MODE, deskey, ips);//ENCRYPT_MODE, data encryption, decryption data DECRYPT_MODE,
Byte [] bOut=cipher. DoFinal (deContent);
S=new String (bOut);
} the catch (Exception e) {
e.printStackTrace();
}
Return s;
}

A small program that WeChat decryption;
Dec: function () {
Var keyHex=CryptoJS. Enc. Base64. Parse (" key ");
Var ivHex=CryptoJS. Enc. Base64. Parse (" iv ");
Var s1=CryptoJS. Enc. Base64. Parse (this. Data. The result)
The console. The log (CryptoJS);
Var decrypted=CryptoJS. DES. Decrypt ({
Ciphertext: CryptoJS enc. Utf8. Parse (s1)
KeyHex}, {
Iv: ivHex,
Mode: CryptoJS. Mode. CBC,
Padding: CryptoJS. Pad. Pkcs7
});
The console. The log (decrypted. ToString ());
Var s=sha1. Sha1 (decrypted. ToString ());//
The console. The log (s);
Return decrypted. ToString ();//
}

The data after decryption, unlike WeChat decryption, turn to the great god answer

CodePudding user response:

With Google's tripledes. Js decryption, files are too big don't pass,
  • Related