Exemplo n.º 1
0
        public void UnlockVolume(string key)
        {
            string eVolume           = File.ReadAllBytes(VolumeLocation).GetString();
            string unlockName        = UnlockLocation + UID;
            string DecVolumeLocation = unlockName + ".dec";

            if (!Directory.Exists(UnlockLocation))
            {
                Directory.CreateDirectory(UnlockLocation);
            }
            if (Directory.Exists(unlockName))
            {
                Directory.Delete(unlockName, true);
            }
            File.WriteAllBytes(DecVolumeLocation, PowerAES.Decrypt(eVolume, key).GetBytes());
            ZipFile.ExtractToDirectory(DecVolumeLocation, unlockName);
            FileWiper fw = new FileWiper();

            fw.PassInfoEvent   += (e) => {};
            fw.SectorInfoEvent += (e) => {};
            fw.WipeDoneEvent   += (e) => {};
            fw.WipeErrorEvent  += (e) => {};
            fw.WipeFile(DecVolumeLocation, 1);
            _unlocked   = true;
            _unlockPath = unlockName;
        }
Exemplo n.º 2
0
        public static int[] DecryptIntData(string encryptedIntData, string password)
        {
            string dB  = Base64.Base64Decode(encryptedIntData);
            string key = PowerAES.SHA512Hash(password);
            string decryptedIntData = PowerAES.Decrypt(dB, key);

            int[] nIntdata = GetIntDataFromBase64(decryptedIntData);
            return(nIntdata);
        }
Exemplo n.º 3
0
        public void Unlock_1_0(string key)
		{
			string unlockName = UnlockLocation+UID;
			string DecVolumeLocation = unlockName+".dec";
			if (!Directory.Exists(UnlockLocation))
			{
				Directory.CreateDirectory(UnlockLocation);
			}
			if (Directory.Exists(unlockName))
			{
				fw.RecursivelyWipeDirectory(unlockName);
				Directory.Delete(unlockName,true);
			}
            string eVolume = File.ReadAllBytes(VolumeLocation).GetString();
            File.WriteAllBytes(DecVolumeLocation, PowerAES.Decrypt(eVolume,key).GetBytes());
			ZipFile.ExtractToDirectory(DecVolumeLocation, unlockName);
			fw.WipeFile(DecVolumeLocation, 1);
			_unlocked = true;
			_unlockPath = unlockName;
		}
Exemplo n.º 4
0
 public void Unlock_2_0(string key)
 {
     string unlockName = UnlockLocation + UID;
     string DecVolumeLocation = unlockName + ".dec";
     if (!Directory.Exists(UnlockLocation))
     {
         Directory.CreateDirectory(UnlockLocation);
     }
     if (Directory.Exists(unlockName))
     {
         fw.RecursivelyWipeDirectory(unlockName);
         Directory.Delete(unlockName, true);
     }
     int bufSize = SelectBufferSize();
     byte[] encryptedFileBuffer = new byte[bufSize]; //128 Mebibytes, 134.2 Megabytes
     byte[] decryptionBuffer1; //128 Mebibytes, 134.2 Megabytes
     //Buffered-read and decrypt and write to the output file
     using (var encryptedFileStream = File.Open(VolumeLocation, FileMode.Open, FileAccess.ReadWrite))
     {
         using (var rawFileStream = File.Open(DecVolumeLocation, FileMode.Create, FileAccess.ReadWrite))
         {
             using (var encryptedFileReader = new BinaryReader(encryptedFileStream))
             {
                 using (var rawFileWriter = new BinaryWriter(rawFileStream))
                 {
                     int bytesRead;
                     while ((bytesRead = encryptedFileReader.Read(encryptedFileBuffer, 0, bufSize)) > 0)
                     {
                         //Slice buffer
                         decryptionBuffer1 = PowerAES.Decrypt(encryptedFileBuffer.Take(bytesRead).ToArray().GetString(), key).GetBytes();
                         rawFileWriter.Write(decryptionBuffer1, 0, decryptionBuffer1.Length);
                     }
                 }
             }
         }
     }
     ZipFile.ExtractToDirectory(DecVolumeLocation, unlockName);
     fw.WipeFile(DecVolumeLocation, 1);
     _unlocked = true;
     _unlockPath = unlockName;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Loads any existing data into the database.
        /// </summary>
        public void LoadDatabase()
        {
            _targetStream.Position = 0;
            var encryptedData = _targetReader.ReadBytes((int)_targetReader.BaseStream.Length);
            var decryptedData = PowerAES.Decrypt(encryptedData.GetString(), EncryptionKey).GetBytes();

            using (var decryptedStream = new MemoryStream(decryptedData))
            {
                switch (SerializationSystem)
                {
                case DatabaseSerializationSystem.MsgPack:
                    Tables = Serializer.Unpack(decryptedStream) as KDBDataStructure;
                    break;

                case DatabaseSerializationSystem.Json:
                    using (var decryptedStreamReader = new StreamReader(decryptedStream))
                    {
                        var jsonString = decryptedStreamReader.ReadToEnd();
                        Tables = JsonConvert.DeserializeObject <KDBDataStructure>(jsonString);
                    }
                    break;
                }
            }
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            const int    rsaKeySize = 728; //Smaller key sizes are easier to generate while testing
            var          prsa       = new PowerRSA(rsaKeySize, PowerRSA.PHashAlgorithm.SHA256);
            const string p          = "this is n";
            var          c          = prsa.EncryptStringWithPublicKey(p);

            Console.WriteLine(c);
            var d = prsa.DecryptStringWithPrivateKey(c);

            Console.WriteLine(d);
            var x = prsa.PublicKey;

            Console.WriteLine("RSAProvider Data: " + prsa.PrivateKey);
            Console.WriteLine("Exporting Private key to PKCS format:");
            var priPemKey = RSAExtensions.ConvertPrivateKeyToPKCS(prsa);

            Console.WriteLine(priPemKey);
            Console.Write("PKCS Signing...");
            const string signData  = "Hello, World!";
            var          signature = RSAExtensions.SignWithPKCSPrivateKey(signData, prsa);

            Console.WriteLine(signature);
            Console.Write("Verifying...");
            var verification = RSAExtensions.VerifyWithPKCSPublicKey(signData, signature, prsa);

            Console.WriteLine(verification);

            prsa.Dispose();

            var pub = new PowerRSA(x, rsaKeySize, PowerRSA.PHashAlgorithm.SHA256);
            var e   = pub.EncryptStringWithPublicKey(p);
            var d2  = prsa.DecryptStringWithPrivateKey(e);

            Console.WriteLine(d2);
            pub.Dispose();
            Console.WriteLine(e);
            const string k  = "1234";
            var          a1 = PowerAES.Encrypt(p, k);

            Console.WriteLine(a1);
            var d1 = PowerAES.Decrypt(a1, k);

            Console.WriteLine(d1);
            Console.WriteLine(PowerAES.SHA512Hash(p));

            Console.WriteLine("Testing AES encryption on strings...");
            var plaintextString = "Hi i like pie";
            var password        = "******";
            var encryptedString = PowerAES.Encrypt(plaintextString, password);
            var decryptedString = PowerAES.Decrypt(encryptedString, password);

            Debug.Assert(decryptedString == plaintextString);

            Console.WriteLine("Testing AES encryption directly on bytes...");
            var aesProvider    = new AESProvider();
            var salt           = aesProvider.GenerateRandomBytes(24);
            var key            = aesProvider.DeriveKeyFromPassphrase("monkey", salt);
            var iv             = aesProvider.GenerateRandomBytes(16); //128-bit IV
            var plaintextBytes = Encoding.UTF8.GetBytes("Hi I am a monkey");
            var encryptedBytes = aesProvider.EncryptBytes(plaintextBytes, key, iv);
            var decryptedBytes = aesProvider.DecryptBytes(iv, salt, encryptedBytes, key);

            Debug.Assert(decryptedBytes.SequenceEqual(plaintextBytes));
            Console.WriteLine("Hash Test");
            var hash = HashUtils.SHA512(k);

            Console.WriteLine(hash);
            Console.WriteLine("Demo completed");
            Console.ReadKey();
        }