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

Last change on this file since 2391 was 1751, checked in by Paul Lelgemann, 11 years ago

+ KeySearcher: added database access for evaluation
+ Added KeySearcher/AES workspaces with different sizes

File size: 2.3 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            // Add simple data
21            var bytesToUse = keySearcher.CostMaster.getBytesToUse();
22            var rawIdentifier = "P2PJOB";
23            rawIdentifier += settings.ChunkSize + settings.Key;
24            rawIdentifier += keySearcher.ControlMaster.GetType();
25            rawIdentifier += keySearcher.CostMaster.GetType();
26            rawIdentifier += bytesToUse;
27            rawIdentifier += keySearcher.CostMaster.getRelationOperator();
28
29            // Add initialization vector when available
30            if (keySearcher.InitVector != null)
31            {
32                rawIdentifier += Encoding.ASCII.GetString(keySearcher.InitVector);
33            }
34
35            // Add input data with the amount of used bytes
36            var inputData = keySearcher.EncryptedData;
37            if (inputData.Length > bytesToUse)
38                Array.Copy(inputData, inputData, bytesToUse);
39
40            rawIdentifier += Encoding.ASCII.GetString(inputData);
41           
42            // Add cost of input data to preserve cost master settings
43            rawIdentifier += keySearcher.CostMaster.calculateCost(inputData);
44
45            /*
46            // Add decrypted input data to preserve encryption settings
47            var keyLength = keySearcher.Pattern.giveInputPattern().Length / 3;
48            var decryptedData = keySearcher.ControlMaster.Decrypt(inputData, new byte[keyLength], new byte[8]);
49            rawIdentifier += Encoding.ASCII.GetString(decryptedData);
50            */
51
52            var hashAlgorithm = new SHA1CryptoServiceProvider();
53            var hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(rawIdentifier));
54            return BitConverter.ToString(hash).Replace("-", "");
55        }
56
57        public string GenerateStatusKey()
58        {
59            return Generate() + "-status";
60        }
61    }
62}
Note: See TracBrowser for help on using the repository browser.