public static string DecryptGDEData(byte[] encryptedContent) { GDECrypto gdeCrypto = null; TextAsset gdeCryptoResource = (TextAsset)Resources.Load(GDMConstants.MetaDataFileName, typeof(TextAsset)); byte[] bytes = Convert.FromBase64String(gdeCryptoResource.text); Resources.UnloadAsset(gdeCryptoResource); using (var stream = new MemoryStream(bytes)) { BinaryFormatter bin = new BinaryFormatter(); gdeCrypto = (GDECrypto)bin.Deserialize(stream); } string content = string.Empty; if (gdeCrypto != null) { content = gdeCrypto.Decrypt(encryptedContent); } return(content); }
static void GenerateKeys() { string path = GDESettings.FullRootDir + Path.DirectorySeparatorChar + GDECodeGenConstants.CryptoFilePath; string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } gdeCrypto = new GDECrypto(); RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); gdeCrypto.Salt = new Byte[SALT_LENGTH]; rng.GetBytes(gdeCrypto.Salt); gdeCrypto.IV = new Byte[IV_LENGTH]; rng.GetBytes(gdeCrypto.IV); byte[] passbytes = new Byte[PASS_LENGTH]; rng.GetBytes(passbytes); gdeCrypto.Pass = Convert.ToBase64String(passbytes); using (var stream = new MemoryStream()) { BinaryFormatter bin = new BinaryFormatter(); bin.TypeFormat = FormatterTypeStyle.XsdString; bin.Serialize(stream, gdeCrypto); File.WriteAllText(path, Convert.ToBase64String(stream.ToArray())); } AssetDatabase.Refresh(); }
static void GenerateKeys() { string path = GDESettings.FullRootDir + Path.DirectorySeparatorChar + GDECodeGenConstants.CryptoFilePath; string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); gdeCrypto = new GDECrypto(); RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); gdeCrypto.Salt = new Byte[SALT_LENGTH]; rng.GetBytes(gdeCrypto.Salt); gdeCrypto.IV = new Byte[IV_LENGTH]; rng.GetBytes(gdeCrypto.IV); byte[] passbytes = new Byte[PASS_LENGTH]; rng.GetBytes(passbytes); gdeCrypto.Pass = Convert.ToBase64String(passbytes); using (var stream = new MemoryStream()) { BinaryFormatter bin = new BinaryFormatter(); bin.TypeFormat = FormatterTypeStyle.XsdString; bin.Serialize(stream, gdeCrypto); File.WriteAllText(path, Convert.ToBase64String(stream.ToArray())); } AssetDatabase.Refresh(); }