Пример #1
0
        internal static void AutoGenKeys()
        {
#if TARGET_J2EE
            {
#else
            try {
                if (autogenerated == null)
                {
                    autogenerated = MachineKeyRegistryStorage.Retrieve(
                        MachineKeyRegistryStorage.KeyType.Validation);
                }
                if (autogenerated_decrypt == null)
                {
                    autogenerated_decrypt = MachineKeyRegistryStorage.Retrieve(
                        MachineKeyRegistryStorage.KeyType.Encryption);
                }
            } catch (Exception) {
#endif
                // Fall back to old method
                RandomNumberGenerator rng = RandomNumberGenerator.Create();

                if (autogenerated == null)
                {
                    autogenerated = new byte [64];
                    rng.GetBytes(autogenerated);
                }

                if (autogenerated_decrypt == null)
                {
                    autogenerated_decrypt = new byte [64];
                    rng.GetBytes(autogenerated_decrypt);
                }
            }
        }
Пример #2
0
        byte[] AutoGenerate(MachineKeyRegistryStorage.KeyType type)
        {
            byte[] key = null;
            try {
                key = MachineKeyRegistryStorage.Retrieve(type);

                // ensure the stored key is usable with the selection algorithm
                if (type == MachineKeyRegistryStorage.KeyType.Encryption)
                {
                    DecryptionTemplate.Key = key;
                }
                else if (type == MachineKeyRegistryStorage.KeyType.Validation)
                {
                    ValidationTemplate.Key = key;
                }
            } catch (Exception) {
                key = null;
            }
            // some algorithms have special needs for key (e.g. length, parity, weak keys...)
            // so we better ask them to provide a default key (than to generate/use bad ones)
            if (key == null)
            {
                if (type == MachineKeyRegistryStorage.KeyType.Encryption)
                {
                    key = DecryptionTemplate.Key;
                }
                else if (type == MachineKeyRegistryStorage.KeyType.Validation)
                {
                    key = ValidationTemplate.Key;
                }
                MachineKeyRegistryStorage.Store(key, type);
            }
            return(key);
        }
Пример #3
0
		byte[] AutoGenerate (MachineKeyRegistryStorage.KeyType type)
		{
			byte[] key = null;
#if TARGET_J2EE
			{
#else
			try {
				key = MachineKeyRegistryStorage.Retrieve (type);

				// ensure the stored key is usable with the selection algorithm
				if (type == MachineKeyRegistryStorage.KeyType.Encryption)
					DecryptionTemplate.Key = key;
				else if (type == MachineKeyRegistryStorage.KeyType.Validation)
					ValidationTemplate.Key = key;
			} catch (Exception) {
				key = null;
			}
#endif
			// some algorithms have special needs for key (e.g. length, parity, weak keys...) 
			// so we better ask them to provide a default key (than to generate/use bad ones)
			if (key == null) {
				if (type == MachineKeyRegistryStorage.KeyType.Encryption)
					key = DecryptionTemplate.Key;
				else if (type == MachineKeyRegistryStorage.KeyType.Validation)
					key = ValidationTemplate.Key;
#if !TARGET_J2EE
				MachineKeyRegistryStorage.Store (key, type);
#endif
			}
			return key;
		}
	}