<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FDevelopment_Class%2FICryptoStream</id>
		<title>Csharp/C Sharp/Development Class/ICryptoStream - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FDevelopment_Class%2FICryptoStream"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Development_Class/ICryptoStream&amp;action=history"/>
		<updated>2026-04-29T21:53:02Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Development_Class/ICryptoStream&amp;diff=1215&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Development_Class/ICryptoStream&amp;diff=1215&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:19Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Development_Class/ICryptoStream&amp;diff=1216&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Development_Class/ICryptoStream&amp;diff=1216&amp;oldid=prev"/>
				<updated>2010-05-26T11:43:30Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Decrypting data.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Security;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class StoreCryptoStream : ICryptoStream {&lt;br /&gt;
    static byte[] tag1 = {(byte)&amp;quot;[&amp;quot;,(byte)&amp;quot;S&amp;quot;,(byte)&amp;quot;a&amp;quot;,(byte)&amp;quot;u&amp;quot; ,(byte)&amp;quot;d&amp;quot; ,(byte)&amp;quot;e&amp;quot;,(byte)&amp;quot;s&amp;quot; ,(byte)&amp;quot;]&amp;quot;};&lt;br /&gt;
    static byte[] tag2 = {(byte)&amp;quot;[&amp;quot;,(byte)&amp;quot;S&amp;quot;,(byte)&amp;quot;a&amp;quot;,(byte)&amp;quot;u&amp;quot; ,(byte)&amp;quot;r&amp;quot; ,(byte)&amp;quot;c&amp;quot;,(byte)&amp;quot;2&amp;quot; ,(byte)&amp;quot;]&amp;quot;};&lt;br /&gt;
    FileStream fs;&lt;br /&gt;
    public StoreCryptoStream(FileStream fout) {&lt;br /&gt;
        fs = fout;&lt;br /&gt;
    }&lt;br /&gt;
    public virtual void CloseStream() { fs.Close(); }&lt;br /&gt;
    public virtual void CloseStream(Object obj) { fs.Close(); }&lt;br /&gt;
    public virtual void SetSink(ICryptoStream pstm) { }&lt;br /&gt;
    public virtual void SetSource(CryptographicObject co) { }&lt;br /&gt;
    public virtual ICryptoStream GetSink() { return null; }&lt;br /&gt;
    public virtual void Write(byte[] bin) {&lt;br /&gt;
        int len = bin.GetLength(0);&lt;br /&gt;
        Write(bin, 0, len);&lt;br /&gt;
    }&lt;br /&gt;
    public virtual void Write(byte[] bin, int start, int len) {&lt;br /&gt;
        fs.Write(bin, start, len);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
    static byte[] symKey;&lt;br /&gt;
    static byte[] symIV;&lt;br /&gt;
    private static bool GenerateKey(string password) {&lt;br /&gt;
            int len;&lt;br /&gt;
            char[] cp = password.ToCharArray();&lt;br /&gt;
            len = cp.GetLength(0);&lt;br /&gt;
            byte[] bt = new byte[len];&lt;br /&gt;
            for (int i = 0; i &amp;lt; len; i++) {&lt;br /&gt;
                bt[i] = (byte)cp[i];&lt;br /&gt;
            }&lt;br /&gt;
            symKey = new byte[8];&lt;br /&gt;
            symIV = new byte[8];&lt;br /&gt;
            SHA1_CSP sha = new SHA1_CSP();&lt;br /&gt;
            sha.Write(bt);&lt;br /&gt;
            sha.CloseStream();&lt;br /&gt;
            for (int i = 0; i &amp;lt; 8; i++) {&lt;br /&gt;
                symKey[i] = sha.Hash[i];&lt;br /&gt;
            }&lt;br /&gt;
            for (int i = 8; i &amp;lt; 16; i++) {&lt;br /&gt;
                symIV[i - 8] = sha.Hash[i];&lt;br /&gt;
            }&lt;br /&gt;
            return true;&lt;br /&gt;
    }&lt;br /&gt;
    private static void DecryptData(string infile, string outfile) {&lt;br /&gt;
            FileStream fin = new FileStream(infile, FileMode.Open, FileAccess.Read);&lt;br /&gt;
            FileStream fout = new FileStream(outfile, FileMode.OpenOrCreate, FileAccess.Write);&lt;br /&gt;
            fout.SetLength(0);&lt;br /&gt;
            byte[] bin = new byte[4096];&lt;br /&gt;
            long totlen = fin.Length;&lt;br /&gt;
            long rdlen = 8;&lt;br /&gt;
            int len;&lt;br /&gt;
            SymmetricAlgorithm des = new DES_CSP();&lt;br /&gt;
            StoreCryptoStream scs = new StoreCryptoStream(fout);&lt;br /&gt;
            SymmetricStreamDecryptor ssd = des.CreateDecryptor(symKey, symIV);&lt;br /&gt;
            ssd.SetSink(scs);&lt;br /&gt;
            scs.SetSource(ssd);&lt;br /&gt;
            while (rdlen &amp;lt; totlen) {&lt;br /&gt;
                len = fin.Read(bin, 0, 4096);&lt;br /&gt;
                ssd.Write(bin, 0, len);&lt;br /&gt;
                rdlen = rdlen + len;&lt;br /&gt;
            }&lt;br /&gt;
            ssd.CloseStream();&lt;br /&gt;
            fin.Close();&lt;br /&gt;
            fout.Close();&lt;br /&gt;
    }&lt;br /&gt;
    public static void Main(string[] args) {&lt;br /&gt;
        GenerateKey(args[0]);&lt;br /&gt;
        DecryptData(args[1], args[2]);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Encrypting data.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Security;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class StoreCryptoStream : ICryptoStream {&lt;br /&gt;
    static byte[] tag1 = {(byte)&amp;quot;[&amp;quot;,(byte)&amp;quot;S&amp;quot;,(byte)&amp;quot;a&amp;quot;,(byte)&amp;quot;u&amp;quot; ,&lt;br /&gt;
        (byte)&amp;quot;d&amp;quot; ,(byte)&amp;quot;e&amp;quot;,(byte)&amp;quot;s&amp;quot; ,(byte)&amp;quot;]&amp;quot;};&lt;br /&gt;
    static byte[] tag2 = {(byte)&amp;quot;[&amp;quot;,(byte)&amp;quot;S&amp;quot;,(byte)&amp;quot;a&amp;quot;,(byte)&amp;quot;u&amp;quot; ,&lt;br /&gt;
        (byte)&amp;quot;r&amp;quot; ,(byte)&amp;quot;c&amp;quot;,(byte)&amp;quot;2&amp;quot; ,(byte)&amp;quot;]&amp;quot;};&lt;br /&gt;
    FileStream fs;&lt;br /&gt;
    public StoreCryptoStream(FileStream fout) {&lt;br /&gt;
        fs = fout;&lt;br /&gt;
    }&lt;br /&gt;
    public virtual void CloseStream() { fs.Close(); }&lt;br /&gt;
    public virtual void CloseStream(Object obj) { fs.Close(); }&lt;br /&gt;
    public virtual void SetSink(ICryptoStream pstm) { }&lt;br /&gt;
    public virtual void SetSource(CryptographicObject co) { }&lt;br /&gt;
    public virtual ICryptoStream GetSink() { return null; }&lt;br /&gt;
    public virtual void Write(byte[] bin) {&lt;br /&gt;
        int len = bin.GetLength(0);&lt;br /&gt;
        Write(bin, 0, len);&lt;br /&gt;
    }&lt;br /&gt;
    public virtual void Write(byte[] bin, int start, int len) {&lt;br /&gt;
        fs.Write(bin, start, len);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
    static byte[] symKey;&lt;br /&gt;
    static byte[] symIV;&lt;br /&gt;
    private static bool GenerateKey(string password) {&lt;br /&gt;
        try {&lt;br /&gt;
            int len;&lt;br /&gt;
            char[] cp = password.ToCharArray();&lt;br /&gt;
            len = cp.GetLength(0);&lt;br /&gt;
            byte[] bt = new byte[len];&lt;br /&gt;
            for (int i = 0; i &amp;lt; len; i++) {&lt;br /&gt;
                bt[i] = (byte)cp[i];&lt;br /&gt;
            }&lt;br /&gt;
            symKey = new byte[8];&lt;br /&gt;
            symIV = new byte[8];&lt;br /&gt;
            SHA1_CSP sha = new SHA1_CSP();&lt;br /&gt;
            sha.Write(bt);&lt;br /&gt;
            sha.CloseStream();&lt;br /&gt;
            for (int i = 0; i &amp;lt; 8; i++) {&lt;br /&gt;
                symKey[i] = sha.Hash[i];&lt;br /&gt;
            }&lt;br /&gt;
            for (int i = 8; i &amp;lt; 16; i++) {&lt;br /&gt;
                symIV[i - 8] = sha.Hash[i];&lt;br /&gt;
            }&lt;br /&gt;
            return true;&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            Console.WriteLine(&amp;quot;An Exception Occurred in Generating eys:&amp;quot;&lt;br /&gt;
                + e.ToString());&lt;br /&gt;
            return false;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    private static void EncryptData(string infile, string outfile) {&lt;br /&gt;
        try {&lt;br /&gt;
            FileStream fin = new FileStream(infile, FileMode.Open, FileAccess.Read);&lt;br /&gt;
            FileStream fout = new FileStream(outfile, FileMode.OpenOrCreate, FileAccess.Write);&lt;br /&gt;
            fout.SetLength(0);&lt;br /&gt;
            byte[] bin = new byte[4096];&lt;br /&gt;
            long totlen = fin.Length;&lt;br /&gt;
            long rdlen = 0;&lt;br /&gt;
            int len;&lt;br /&gt;
            SymmetricAlgorithm des = new DES_CSP();&lt;br /&gt;
            StoreCryptoStream scs = new StoreCryptoStream(fout);&lt;br /&gt;
            SymmetricStreamEncryptor sse = des.CreateEncryptor(symKey, symIV);&lt;br /&gt;
            SHA1_CSP sha = new SHA1_CSP();&lt;br /&gt;
            sse.SetSink(sha);&lt;br /&gt;
            sha.SetSource(sse);&lt;br /&gt;
            sha.SetSink(scs);&lt;br /&gt;
            scs.SetSource(sha);&lt;br /&gt;
            while (rdlen &amp;lt; totlen) {&lt;br /&gt;
                len = fin.Read(bin, 0, 4096);&lt;br /&gt;
                sse.Write(bin, 0, len);&lt;br /&gt;
                rdlen = rdlen + len;&lt;br /&gt;
            }&lt;br /&gt;
            sse.CloseStream();&lt;br /&gt;
            fin.Close();&lt;br /&gt;
            fout.Close();&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            Console.WriteLine(&amp;quot;An exception occurred while encrypting :&amp;quot;&lt;br /&gt;
                 + e.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static void Main(string[] args) {&lt;br /&gt;
        GenerateKey(args[0]);&lt;br /&gt;
        EncryptData(args[1], args[2]);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>