public static string GetDecompressedData(byte[] data) { if (CompressionUtility.GetDecompressedDataExtern != null) { return(CompressionUtility.GetDecompressedDataExtern(data)); } return("Error - GetDecompressedData callback not declared"); }
public string Encrypt() { byte[] bytes = this.SaveToMemory(); bytes = CompressionUtility.Compress(bytes); string result = Convert.ToBase64String(bytes); return(result); }
public void Compress(string body) { var uncompressedBytes = Encoding.UTF8.GetBytes(body); var compressedBytes = CompressionUtility.Compress(uncompressedBytes); var isCompressed = compressedBytes.Length < uncompressedBytes.Length; CompressionType = isCompressed ? CompressionType.Gzip : CompressionType.None; Bytes = isCompressed ? compressedBytes : uncompressedBytes; }
public byte[]? GetContent(CompressionMethod compressionMethod) { // If there are both entity tag and content, use them. switch (compressionMethod) { case CompressionMethod.Deflate: if (_deflatedContent != null) { return(_deflatedContent); } break; case CompressionMethod.Gzip: if (_gzippedContent != null) { return(_gzippedContent); } break; case CompressionMethod.None: if (_uncompressedContent != null) { return(_uncompressedContent); } break; default: throw SelfCheck.Failure($"Unexpected compression method {compressionMethod}."); } // Try to convert existing content, if any. byte[]? content; if (_uncompressedContent != null) { content = CompressionUtility.ConvertCompression(_uncompressedContent, CompressionMethod.None, compressionMethod); } else if (_gzippedContent != null) { content = CompressionUtility.ConvertCompression(_gzippedContent, CompressionMethod.Gzip, compressionMethod); } else if (_deflatedContent != null) { content = CompressionUtility.ConvertCompression(_deflatedContent, CompressionMethod.Deflate, compressionMethod); } else { // No content whatsoever. return(null); } return(SetContent(compressionMethod, content)); }
/// <summary> /// Decrypt the connection settings. /// </summary> public static ConnectionSettings Decrypt ( [NotNull] string text ) { Sure.NotNull(text, nameof(text)); byte[] bytes = Convert.FromBase64String(text); bytes = CompressionUtility.Decompress(bytes); ConnectionSettings result = bytes.RestoreObjectFromMemory <ConnectionSettings>(); return(result); }
void Awake() { FileStream fileStream = new FileStream(Application.persistentDataPath + "/" + CONFIG_PATH, FileMode.Open); MemoryStream uncompressedStream = new MemoryStream(); CompressionUtility.DecompressStream(fileStream, uncompressedStream); BinaryFormatter bft = new BinaryFormatter(); DataResource.Resource = (DataSet)bft.Deserialize(uncompressedStream); fileStream.Close(); uncompressedStream.Close(); }
private string Encrypt(string plainText, string password) { byte[] salt = Encoding.Unicode.GetBytes(Salt); byte[] plainBytes = Encoding.Unicode.GetBytes(Compressed ? CompressionUtility.GZipCompress(plainText) : plainText); var aes = Aes.Create(); var pbkdf2 = new Rfc2898DeriveBytes(password, salt, Iterations); aes.Key = pbkdf2.GetBytes(32); // set a 256-bit key aes.IV = pbkdf2.GetBytes(16); // set a 128-bit IV var ms = new MemoryStream(); using (var cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(plainBytes, 0, plainBytes.Length); } return(Convert.ToBase64String(ms.ToArray())); }
private string Decrypt(string cryptoText, string password) { byte[] salt = Encoding.Unicode.GetBytes(Salt); byte[] cryptoBytes = Convert.FromBase64String(Compressed ? CompressionUtility.GZipCompress(cryptoText) : cryptoText); var aes = Aes.Create(); var pbkdf2 = new Rfc2898DeriveBytes(password, salt, Iterations); aes.Key = pbkdf2.GetBytes(32); aes.IV = pbkdf2.GetBytes(16); var ms = new MemoryStream(); using (var cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(cryptoBytes, 0, cryptoBytes.Length); } return(Encoding.Unicode.GetString(ms.ToArray())); }
public string Decompress() { byte[] decompressed; switch (CompressionType) { case CompressionType.Gzip: decompressed = CompressionUtility.Decompress(Bytes); break; case CompressionType.None: decompressed = Bytes; break; default: throw new NotImplementedException(); } return(Encoding.UTF8.GetString(decompressed)); }
void Awake() { FileStream fileStream = new FileStream(Application.persistentDataPath + "/" + CONFIG_PATH, FileMode.Open); /* * BinaryWriter writer = new BinaryWriter(fileStream); * writer.Write(this.m_wwwConfigTable.bytes); * writer.Close(); */ MemoryStream uncompressedStream = new MemoryStream(); CompressionUtility.DecompressStream(fileStream, uncompressedStream); BinaryFormatter bft = new BinaryFormatter(); DataResource.Resource = (DataSet)bft.Deserialize(uncompressedStream); fileStream.Close(); uncompressedStream.Close(); }
public unsafe static long $Invoke0(long instance, long *args) { return(GCHandledObjects.ObjectToGCHandle(CompressionUtility.GetDecompressedData((byte[])GCHandledObjects.GCHandleToPinnedArrayObject(*args)))); }
IEnumerator Initialize() { CommunicationUtility.Instance.DisconnectToServer(); CommunicationUtility.Instance.ConnectToServer(); while (!CommunicationUtility.Instance.IsConnectedToServer) { yield return(null); } VersionRequestParameter request = new VersionRequestParameter(); request.PlatformType = CommonHelper.PlatformType; CommunicationUtility.Instance.GetVersion(this, "ReceivedVersion", true, request); while (!this.IsGetServerVersion) { yield return(null); } if (CommonHelper.PlatformType == ConfigUtilities.Enums.PlatformType.iOS) { if (iOSCenter.Instance.AccountID < 0) { this.m_UIWindowUserLogin.ShowWindow(); } while (iOSCenter.Instance.AccountID < 0) { yield return(null); } } AudioController.PlayMusic("Loading"); this.m_ProgressBar.SetActive(true); CommunicationUtility.Instance.GetConfigTableMD5(this, "ReceivedConfigTableMD5", true); while (!this.IsGetServerMD5) { yield return(null); } this.LoadConfigTable(); byte[] localMD5 = null; if (this.m_wwwConfigTable != null) { while (!this.m_wwwConfigTable.isDone) { yield return(null); } MemoryStream ms = new MemoryStream(this.m_wwwConfigTable.bytes); localMD5 = MD5.Create().ComputeHash(ms); ms.Close(); } if (localMD5 == null || !localMD5.IsEqualByteArray(this.m_ServerConfigTableMD5)) { string configUrl = string.Format(DataResource.CONFIG_TABLE_URL, ClientVersion.Instance.Version); this.m_wwwConfigTable = new WWW(configUrl); yield return(this.m_wwwConfigTable); } FileStream fileStream = new FileStream(Application.persistentDataPath + "/" + CONFIG_PATH, FileMode.Create); BinaryWriter writer = new BinaryWriter(fileStream); writer.Write(this.m_wwwConfigTable.bytes); writer.Close(); MemoryStream compressedStream = new MemoryStream(this.m_wwwConfigTable.bytes); MemoryStream uncompressedStream = new MemoryStream(); CompressionUtility.DecompressStream(compressedStream, uncompressedStream); BinaryFormatter bft = new BinaryFormatter(); DataResource.Resource = (DataSet)bft.Deserialize(uncompressedStream); /* * print(DataResource.Resource.Tables.Count); * print(DataResource.Resource.Tables[0].Rows.Count); * print(DataResource.Resource.Tables[1].Rows.Count); * print(DataResource.Resource.Tables[2].Rows.Count); */ compressedStream.Close(); uncompressedStream.Close(); if (CommonHelper.PlatformType == ConfigUtilities.Enums.PlatformType.iOS && Application.platform == RuntimePlatform.IPhonePlayer) { ((iOSShopUtility)(iOSShopUtility.Instance)).RequestProduct(); } this.m_UserIntializer.StartInitialize(); }
private void GetFilesToKeep(string sdk) { var myFiles = new List <string>(); string compressedArchivePath = Path.Combine(mSdksFolder, sdk, "nuGetPackagesArchive.lzma"); Console.WriteLine("Decompressing " + compressedArchivePath); using (var archiveStream = CreateTemporaryFileStream()) { // decompress the LZMA stream using (var lzmaStream = File.OpenRead(compressedArchivePath)) { var progress = new MyProgress(); CompressionUtility.Decompress(lzmaStream, archiveStream, progress); } // reset the uncompressed stream archiveStream.Seek(0, SeekOrigin.Begin); Console.WriteLine("Rooting files in " + compressedArchivePath); // read as a zip archive using (var archive = new ZipArchive(archiveStream, ZipArchiveMode.Read)) { var indexEntry = archive.GetEntry(IndexFileName); using (var indexReader = new StreamReader(indexEntry.Open())) { for (var line = indexReader.ReadLine(); line != null; line = indexReader.ReadLine()) { var lineParts = line.Split(pipeSeperator); if (lineParts.Length != 2) { throw new Exception("Unexpected index line format, too many '|'s."); } string target = lineParts[0]; string source = lineParts[1]; var zipSeperatorIndex = target.IndexOf("::", StringComparison.OrdinalIgnoreCase); string destinationPath; if (zipSeperatorIndex != -1) { string zipRelativePath = target.Substring(0, zipSeperatorIndex); destinationPath = Path.Combine(mFallbackFolder, zipRelativePath); } else { destinationPath = Path.Combine(mFallbackFolder, target); } //Normalize path (forward slash to backslash) myFiles.Add(Path.GetFullPath(destinationPath)); } } } } lock (mFilesToKeep) { foreach (var f in myFiles) { mFilesToKeep.Add(f); } } }