Decrypt() public method

public Decrypt ( byte cipherTextBytes ) : byte[]
cipherTextBytes byte
return byte[]
Ejemplo n.º 1
0
        public bool LoadCredentials( )
        {
            if (!DPAPI.CanUseDPAPI)
            {
                return(false);
            }
            if (File.Exists(PersistFile))
            {
                byte[] cipher;
                using (FileStream stream = new FileStream(PersistFile, FileMode.Open, FileAccess.Read, FileShare.None))
                    using (BinaryReader reader = new BinaryReader(stream)) {
                        int length = reader.ReadInt32( );
                        cipher = reader.ReadBytes(length);
                    }

                DPAPI dpapi = new DPAPI( );
                dpapi.Entropy = GetEntropy( );

                try {
                    byte[] data = dpapi.Decrypt(cipher);

                    using (MemoryStream stream = new MemoryStream(data))
                        using (BinaryReader reader = new BinaryReader(stream)) {
                            Username = reader.ReadString( );
                            Password = reader.ReadString( );
                        }
                } catch (Exception) {
                    return(false);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public bool LoadCredentials( )
        {
            if ( !DPAPI.CanUseDPAPI )
                return false;
            if ( File.Exists ( PersistFile ) ) {
                byte[] cipher;
                using ( FileStream stream = new FileStream ( PersistFile, FileMode.Open, FileAccess.Read, FileShare.None ) )
                using ( BinaryReader reader = new BinaryReader ( stream ) ) {
                    int length = reader.ReadInt32 ( );
                    cipher = reader.ReadBytes ( length );
                }

                DPAPI dpapi = new DPAPI ( );
                dpapi.Entropy = GetEntropy ( );

                try {
                    byte[] data = dpapi.Decrypt ( cipher );

                    using ( MemoryStream stream = new MemoryStream ( data ) )
                    using ( BinaryReader reader = new BinaryReader ( stream ) ) {
                        Username = reader.ReadString ( );
                        Password = reader.ReadString ( );
                    }
                } catch ( Exception ) {
                    return false;
                }

                return true;
            } else
                return false;
        }