source: trunk/CrypPlugins/KeySearcher/P2P/Storage/StorageKeyGenerator.cs @ 1698

Last change on this file since 1698 was 1698, checked in by Paul Lelgemann, 12 years ago

o Refactoring in CrypP2P
o AES: NullReference in AES-Plugin fixed
o Small fixes in KeySearcher, StorageKeyGenerator uses IV and truncates input data

File size: 1.6 KB
Line 
1using System;
2using System.Security.Cryptography;
3using System.Text;
4
5namespace KeySearcher.P2P.Storage
6{
7    class StorageKeyGenerator
8    {
9        private readonly KeySearcher keySearcher;
10        private readonly KeySearcherSettings settings;
11
12        public StorageKeyGenerator(KeySearcher keySearcher, KeySearcherSettings settings)
13        {
14            this.keySearcher = keySearcher;
15            this.settings = settings;
16        }
17
18        public String Generate()
19        {
20            var bytesToUse = keySearcher.CostMaster.getBytesToUse();
21            var rawIdentifier = "P2PJOB";
22            rawIdentifier += settings.ChunkSize + settings.Key;
23            rawIdentifier += keySearcher.ControlMaster.GetType();
24            rawIdentifier += keySearcher.CostMaster.GetType();
25            rawIdentifier += bytesToUse;
26            rawIdentifier += keySearcher.CostMaster.getRelationOperator();
27
28            if (keySearcher.InitVector != null)
29            {
30                rawIdentifier += Encoding.ASCII.GetString(keySearcher.InitVector);
31            }
32
33            var inputData = Encoding.ASCII.GetString(keySearcher.EncryptedData);
34            if (inputData.Length > bytesToUse)
35            {
36                inputData = inputData.Substring(0, bytesToUse);
37            }
38
39            rawIdentifier += inputData;
40
41            var hashAlgorithm = new SHA1CryptoServiceProvider();
42            var hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(rawIdentifier));
43            return BitConverter.ToString(hash).Replace("-", "");
44        }
45    }
46}
Note: See TracBrowser for help on using the repository browser.