Menu

[r40]: / trunk / WhatsappClient / WhatsAppProtocol / Helper Classes / Encryption.cs  Maximize  Restore  History

Download this file

48 lines (41 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
static class Encryption
{
public static RC4 encryptionOutgoing = null;
public static RC4 encryptionIncoming = null;
public static byte[] WhatsappEncrypt(byte[] key, byte[] data, bool appendHash)
{
if (encryptionOutgoing == null)
encryptionOutgoing = new RC4(key, 256);
HMACSHA1 h = new HMACSHA1(key);
byte[] buff = new byte[data.Length];
Buffer.BlockCopy(data, 0, buff, 0, data.Length);
encryptionOutgoing.Cipher(buff);
byte[] hashByte = h.ComputeHash(buff);
byte[] response = new byte[4 + buff.Length];
if (appendHash)
{
Buffer.BlockCopy(buff, 0, response, 0, buff.Length);
Buffer.BlockCopy(hashByte, 0, response, buff.Length, 4);
}
else
{
Buffer.BlockCopy(hashByte, 0, response, 0, 4);
Buffer.BlockCopy(buff, 0, response, 4, buff.Length);
}
return response;
}
public static byte[] WhatsappDecrypt(byte[] key, byte[] data)
{
if (encryptionIncoming == null)
encryptionIncoming = new RC4(key, 256);
byte[] buff = new byte[data.Length];
Buffer.BlockCopy(data, 0, buff, 0, data.Length);
encryptionIncoming.Cipher(buff);
return buff;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.