public void SyncImpl_DecompressNullArray_ReturnsNull(Type type) { impl = GetImpl(type); byte[] result = impl.Decompress(null, COMPRESSION_SETTINGS); Assert.Null(result); }
public void SyncImpl_DecompressEmptyArray_ReturnsEmptyArray(Type type) { impl = GetImpl(type); byte[] empty = new byte[0]; byte[] result = impl.Decompress(empty, COMPRESSION_SETTINGS); Assert.Empty(result); }
public void SyncImpl_DecompressCompressedString_ReturnsOriginalString(Type type) { impl = GetImpl(type); const string STRING = "mcvlmoqepoir4298DMKfgfgdKNEInofndogoidnoigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuebujfneufsbunskjdfkje"; string compressed = impl.Compress(STRING); Assert.Equal(STRING, impl.Decompress(compressed)); }
public void SyncImpl_CompressDataAndThenDecompress_ResultIdenticalData(Type type) { impl = GetImpl(type); byte[] data = new byte[1024 * 1024]; for (int i = data.Length - 1; i >= 0; i--) { data[i] = (byte)(new Random().NextDouble() > 0.5d ? 5 : 75); } var compressionSettings = new CompressionSettings { bufferSize = 1024 }; byte[] compressed = impl.Compress(data, compressionSettings); byte[] decompressed = impl.Decompress(compressed, compressionSettings); Assert.Equal(data, decompressed); }
/// <summary> /// Decompresses and decrypts a private RSA key /// that was encrypted and compressed using <see cref="EncryptAndCompressPrivateKey"/>, /// ready to be assigned to <see cref="User.PrivateKeyPem"/>. /// </summary> /// <param name="encryptedCompressedKey">The encrypted and compressed private key that you'd get from/to the backend (THE SERVER NEVER HAS YOUR PRIVATE KEY IN PLAIN TEXT).</param> /// <param name="userPassword">The user's password (NOT the hash).</param> /// <returns>The raw PEM-formatted private RSA Key (ready to be assigned to <see cref="User.PrivateKeyPem"/>).</returns> public string DecompressAndDecryptPrivateKey(string encryptedCompressedKey, string userPassword) { return(aes.DecryptWithPassword(compressionUtility.Decompress(encryptedCompressedKey), userPassword)); }