Esempio n. 1
0
 public void SetRSAParameters(RSAParameters rsa)
 {
     //if (this.rsa == null) {
     this.rsa      = rsa;
     meta          = new RSAEncryptingKeyValueStorage(eMeta, rsa);
     symmetricKeys = new RSAEncryptingKeyValueStorage(eSymmetricKeys, rsa);
     try {
         eMeta.Get(System.Text.Encoding.Unicode.GetBytes("RepositoryConfigurationsKeyID").SHA256());
     } catch {
         byte[] id  = new byte[32];
         byte[] key = new byte[32];
         RandomNumberGenerator rng = RandomNumberGenerator.Create();
         rng.GetBytes(id);
         rng.GetBytes(key);
         symmetricKeys.Put(id, key);
         meta.Put(System.Text.Encoding.Unicode.GetBytes("RepositoryConfigurationsKeyID").SHA256(), id);
     }
     if (rsa.InverseQ != null)
     {
         repositoryConfigurations = new AESEncryptingKeyValueStorage(eRepositoryConfigurations,
                                                                     symmetricKeys.Get(meta.Get(System.Text.Encoding.Unicode.GetBytes("RepositoryConfigurationsKeyID").SHA256())));
     }
     //} else
     //	throw new InvalidOperationException ();
 }
Esempio n. 2
0
        public KeyValueStorage <byte[]> GetStore(string name)
        {
            if (stores.ContainsKey(name))
            {
                return(stores [name]);
            }
            KeyValueStorage <byte[]> store = new LevelDBKeyValueStorage(path.CreatePath(name));

            System.IO.MemoryStream ms = new System.IO.MemoryStream(repositoryConfigurations.Get
                                                                       (System.Text.Encoding.Unicode.GetBytes(name)));
            System.Xml.Serialization.XmlSerializer xmls = new System.Xml.Serialization.XmlSerializer(typeof(GenericUserRepositoryConfiguration));
            GenericUserRepositoryConfiguration     gurc = (GenericUserRepositoryConfiguration)xmls.Deserialize(ms);

            switch (gurc.EncryptionMehtod)
            {
            case  EncryptionMethod.AES:
                store = new AESEncryptingKeyValueStorage(store, symmetricKeys.Get(gurc.AESKeyID));
                stores.Add(name, store);
                return(store);

            case EncryptionMethod.RSA:
                store = new RSAEncryptingKeyValueStorage(store, rsa.Value);
                stores.Add(name, store);
                return(store);

            case EncryptionMethod.None:
                stores.Add(name, store);
                return(store);

            default:
                throw new NotSupportedException("Specified encryption method is not supported.");
            }
        }