示例#1
1
		private static void DecryptFile(string filepath) {
			Console.WriteLine("-------------------------");
			Console.WriteLine("File: " + Path.GetFileName(filepath));
			Console.WriteLine("-------------------------");
			Console.WriteLine("Encrypt as flash object? (Y/N)");
			bool isFlashObj = Console.ReadLine().Trim().ToLower() == "y";

			string filename = Path.GetFileNameWithoutExtension(filepath);

			// Base64 decode
			byte[] encodedBuf;
			using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(filepath))) {
				FromBase64Transform trans = new FromBase64Transform();
				using (CryptoStream cryptStream = new CryptoStream(ms, trans, CryptoStreamMode.Read)) {
					byte[] buf = new byte[1024];
					int read = 0;
					using (MemoryStream msResult = new MemoryStream()) {
						do {
							read = cryptStream.Read(buf, 0, buf.Length);
							if (read > 0) {
								msResult.Write(buf, 0, read);
							}
						} while (read > 0);

						encodedBuf = msResult.ToArray();
					}
				}
			}

			// Flash objects needs to be pulled via Flash Decompiler..
			if (isFlashObj) {
				string flashObjPath = Path.Combine(Directory.GetCurrentDirectory(), filename + ".swf");
				if (File.Exists(flashObjPath)) {
					File.Delete(flashObjPath);
				}
				File.WriteAllBytes(flashObjPath, encodedBuf);

				Console.WriteLine("Data exported to \"" + Path.GetFileName(flashObjPath) + "\"");
				Console.Read();
				return;
			}

			// Decrypt real XML using BlowFish algo
			string keyFromDummyAs = "O99vUyAPaGXHNo";
			using (MemoryStream streamDataEncoded = new MemoryStream(encodedBuf)) {
				var keyData = Encoding.UTF8.GetBytes(keyFromDummyAs);
				var pkcs = new PKCS5();
				var blowKey = new BlowFishKey(keyData);
				var ecbMode = new ECBMode(blowKey, pkcs);
				pkcs.BlockSize = ecbMode.BlockSize;
				byte[] bufFinal = ecbMode.Decrypt(streamDataEncoded);

				string xmlPath = Path.Combine(Directory.GetCurrentDirectory(), filename + ".xml");
				if (File.Exists(xmlPath)) {
					File.Delete(xmlPath);
				}
				File.WriteAllBytes(xmlPath, bufFinal);
			}

		}
示例#2
1
		public ECBMode(BlowFishKey bKey, PKCS5 pkcs5) {
			mKey = bKey;
			mPadding = pkcs5;
			mPadding.BlockSize = mKey.BlockSize;
		}
示例#3
0
        /// <summary>
        /// Creates a new PassphrasePrng from a passphrase and salt,
        /// and seeds it with the output of PKCS5
        /// </summary>
        ///
        /// <param name="Digest">Digest engine</param>
        /// <param name="Passphrase">The passphrase</param>
        /// <param name="Salt">The salt value</param>
        /// <param name="Iterations">The number of transformation iterations performed by the digest with PKCS5 (default is 10,000)</param>
        /// <param name="DisposeEngine">Dispose of digest engine when <see cref="Dispose()"/> on this class is called (default is true)</param>
        ///
        /// <exception cref="CryptoRandomException">Thrown if a null Digest, Passphrase or Salt are used</exception>
        public PBPRng(IDigest Digest, byte[] Passphrase, byte[] Salt, int Iterations = PKCS_ITERATIONS, bool DisposeEngine = true)
        {
            if (Digest == null)
            {
                throw new CryptoRandomException("PBPRng:Ctor", "Digest can not be null!", new ArgumentNullException());
            }
            if (Passphrase == null)
            {
                throw new CryptoRandomException("PBPRng:Ctor", "Passphrase can not be null!", new ArgumentNullException());
            }
            if (Salt == null)
            {
                throw new CryptoRandomException("PBPRng:Ctor", "Salt can not be null!", new ArgumentNullException());
            }

            try
            {
                _disposeEngine = DisposeEngine;
                PKCS5 pkcs = new PKCS5(Digest, Iterations, false);
                _digest = Digest;
                pkcs.Initialize(Salt, Passphrase);
                _rndData = new byte[_digest.BlockSize];
                pkcs.Generate(_rndData);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            _position = 0;
        }