Ejemplo n.º 1
0
        public void SyncImpl_CompressNullArray_ReturnsNull(Type type)
        {
            impl = GetImpl(type);

            byte[] result = impl.Compress(null, COMPRESSION_SETTINGS);
            Assert.Null(result);
        }
Ejemplo n.º 2
0
        public void SyncImpl_CompressNullOrEmptyString_ReturnsNull(Type type, string s)
        {
            impl = GetImpl(type);

            string result = impl.Compress(s);

            Assert.Null(result);
        }
Ejemplo n.º 3
0
        public void SyncImpl_CompressEmptyArray_ReturnsEmptyArray(Type type)
        {
            impl = GetImpl(type);

            byte[] empty  = new byte[0];
            byte[] result = impl.Compress(empty, COMPRESSION_SETTINGS);
            Assert.Empty(result);
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        public void SyncImpl_CompressLongString_ReturnsSmallerString(Type type)
        {
            impl = GetImpl(type);

            const string STRING     = "mcvlmoqepoir4298DMKEKNKNEInofndogoidnoigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuigorenoigniofoienoign983874389759835978465798469kdnfndiiudjfbniuebujfneufsbunskjdfkje";
            string       compressed = impl.Compress(STRING);

            Assert.True(compressed.Length < STRING.Length);
        }
Ejemplo n.º 6
0
        public void SyncImpl_Compress5MB_ResultSmallerThanOriginal(Type type)
        {
            impl = GetImpl(type);

            byte[] data = new byte[1024 * 1024 * 5];
            for (int i = data.Length - 1; i >= 0; i--)
            {
                data[i] = (byte)(new Random().NextDouble() > 0.5d ? 5 : 75);
            }

            byte[] result = impl.Compress(data, new CompressionSettings {
                bufferSize = 1024
            });
            Assert.True(result.Length < data.Length);
        }
Ejemplo n.º 7
0
        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>
 /// Encrypts <paramref name="privateKeyPem"/> into a portable <c>string</c>
 /// that is safe to exchange with the backend, AS LONG AS THE USER'S PASSWORD IS NOT COMPROMISED.<para> </para>
 /// THE SERVER NEVER HAS YOUR PRIVATE KEY IN PLAIN TEXT!<para> </para>
 /// The private key is encrypted using the user's password, NOT ITS HASH!
 /// Otherwise the server could decrypt the key, because it does have the user's <see cref="User.PasswordSHA512"/>.<para> </para>
 /// Because of this, it is highly advisable to change user passwords often and use an offline, open-source password manager (such as KeePass).
 /// </summary>
 /// <seealso cref="User"/>
 /// <seealso cref="ISymmetricCryptography"/>
 /// <seealso cref="IAsymmetricCryptographyRSA"/>
 /// <seealso cref="IUserService"/>
 /// <seealso cref="IConvoService"/>
 /// <param name="privateKeyPem">The user's private RSA key (PEM-formatted <c>string</c>).</param>
 /// <param name="userPassword">The user's password (NOT its SHA512!).</param>
 /// <returns><c>string</c> that contains the encrypted and compressed <paramref name="privateKeyPem"/>.</returns>
 public string EncryptAndCompressPrivateKey(string privateKeyPem, string userPassword)
 {
     return(compressionUtility.Compress(aes.EncryptWithPassword(privateKeyPem, userPassword)));
 }