本文整理汇总了C#中System.Security.Cryptography.CryptoStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# CryptoStream.ReadByte方法的具体用法?C# CryptoStream.ReadByte怎么用?C# CryptoStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.CryptoStream
的用法示例。
在下文中一共展示了CryptoStream.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decrypt
public byte[] Decrypt(byte[] cipher, byte[] key, byte[] IV)
{
System.Collections.Generic.List<byte> bytes = new List<byte>();
using (AesManaged _aesAlgorithm = new AesManaged())
{
_aesAlgorithm.Key = key;
_aesAlgorithm.IV = IV;
using (ICryptoTransform decryptor = _aesAlgorithm.CreateDecryptor(_aesAlgorithm.Key, _aesAlgorithm.IV))
{
using (System.IO.MemoryStream str = new System.IO.MemoryStream(cipher))
{
using (CryptoStream crypto = new CryptoStream(str, decryptor, CryptoStreamMode.Read))
{
int b = crypto.ReadByte();
while (b > -1)
{
b = crypto.ReadByte();
bytes.Add((byte)b);
}
}
}
_aesAlgorithm.Clear();
}
}
return bytes.ToArray();
}
示例2: DecryptText
public static string DecryptText(string encryptedText)
{
try
{
RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
ICryptoTransform decryptor = rc2CSP.CreateDecryptor(Convert.FromBase64String(C_KEY), Convert.FromBase64String(C_IV));
MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(encryptedText));
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
List<Byte> bytes = new List<byte>();
int b;
do
{
b = csDecrypt.ReadByte();
if (b != -1)
{
bytes.Add(Convert.ToByte(b));
}
} while (b != -1);
return Encoding.Unicode.GetString(bytes.ToArray());
}
catch (Exception)
{
return "";
}
}
示例3: DecryptFile
public static void DecryptFile(string inputFile, string outputFile, string skey)
{
RijndaelManaged aes = new RijndaelManaged();
try
{
byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);
using (FileStream fsCrypt = new FileStream(inputFile, FileMode.Open))
{
using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
{
using (CryptoStream cs = new CryptoStream(fsCrypt, aes.CreateDecryptor(key, key), CryptoStreamMode.Read))
{
int data;
while ((data = cs.ReadByte()) != -1)
{
fsOut.WriteByte((byte)data);
}
aes.Clear();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
aes.Clear();
}
}
示例4: DecryptFile
public static void DecryptFile(string inputFile, string outputFile, string password)
{
{
var unicodeEncoding = new UnicodeEncoding();
byte[] key = unicodeEncoding.GetBytes(FormatPassword(password));
if (!File.Exists(inputFile))
{
File.Create(inputFile);
}
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
var rijndaelManaged = new RijndaelManaged();
var cryptoStream = new CryptoStream(fsCrypt, rijndaelManaged.CreateDecryptor(key, key), CryptoStreamMode.Read);
var fileStream = new FileStream(outputFile, FileMode.Create);
try
{
int data;
while ((data = cryptoStream.ReadByte()) != -1)
fileStream.WriteByte((byte)data);
}
catch { throw; }
finally
{
fsCrypt.Close();
fileStream.Close();
cryptoStream.Close();
}
}
}
示例5: Decrypt
public static string Decrypt(this string encrypted)
{
if (string.IsNullOrEmpty(encrypted)) { return string.Empty; }
RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
ICryptoTransform decryptor = rc2CSP.CreateDecryptor(Convert.FromBase64String(Key), Convert.FromBase64String(IV));
using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(encrypted)))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
List<Byte> bytes = new List<byte>();
int b;
do
{
b = csDecrypt.ReadByte();
if (b != -1)
{
bytes.Add(Convert.ToByte(b));
}
}
while (b != -1);
return Encoding.Unicode.GetString(bytes.ToArray());
}
}
}
示例6: DecryptPassword
public static string DecryptPassword(string encryptedText)
{
RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
ICryptoTransform decryptor = rc2CSP.CreateDecryptor(rc2CSP.Key, rc2CSP.IV);
using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(encryptedText)))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
List<Byte> bytes = new List<byte>();
int b;
do
{
b = csDecrypt.ReadByte();
if (b != -1)
{
bytes.Add(Convert.ToByte(b));
}
}
while (b != -1);
return Encoding.Unicode.GetString(bytes.ToArray());
}
}
}
示例7: ReadFile
/// <summary>
/// Ghi license ra file
/// </summary>
/// <param name="FilePath"></param>
/// <returns></returns>
public static string ReadFile(string FilePath)
{
try
{
FileInfo fi = new FileInfo(FilePath);
if (fi.Exists == false)
return string.Empty;
FileStream fin = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
TripleDES tdes = new TripleDESCryptoServiceProvider();
CryptoStream cs = new CryptoStream(fin, tdes.CreateDecryptor(key, iv), CryptoStreamMode.Read);
StringBuilder SB = new StringBuilder();
int ch;
for (int i = 0; i < fin.Length; i++)
{
ch = cs.ReadByte();
if (ch == 0)
break;
SB.Append(Convert.ToChar(ch));
}
cs.Close();
fin.Close();
return SB.ToString();
}
catch(Exception ex)
{
return "";
}
}
示例8: Decrypt
public static void Decrypt(string srcPath, string destPath, int salt, string encryptionKey)
{
DeriveBytes rgb = new Rfc2898DeriveBytes(encryptionKey, Encoding.Unicode.GetBytes(salt.ToString()));
using (SymmetricAlgorithm aes = new RijndaelManaged())
{
aes.BlockSize = 128;
aes.KeySize = 256;
aes.Key = rgb.GetBytes(aes.KeySize >> 3);
aes.IV = rgb.GetBytes(aes.BlockSize >> 3);
aes.Mode = CipherMode.CBC;
Console.WriteLine("key : {0} , IV {1}\n", aes.Key.Length, aes.IV.Length);
using (FileStream fsCrypt = new FileStream(srcPath, FileMode.Open))
{
using (FileStream fsOut = new FileStream(destPath, FileMode.Create))
{
using (ICryptoTransform decryptor = aes.CreateDecryptor())
{
using (CryptoStream cs = new CryptoStream(fsCrypt, decryptor, CryptoStreamMode.Read))
{
int data;
while ((data = cs.ReadByte()) != -1)
{
fsOut.WriteByte((byte)data);
}
}
}
}
}
}
}
示例9: DecryptFile
public static void DecryptFile(string inputFile, string outputFile, string skey)
{
try
{
using (Aes aes = new AesManaged() { KeySize = 256, BlockSize = 128 })
{
var key = new Rfc2898DeriveBytes(skey, salt);
aes.Key = key.GetBytes(aes.KeySize / 8);
aes.IV = key.GetBytes(aes.BlockSize / 8);
using (FileStream fsCrypt = new FileStream(inputFile, FileMode.Open))
{
using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
{
using (ICryptoTransform decryptor = aes.CreateDecryptor())
{
using (CryptoStream cs = new CryptoStream(fsCrypt, decryptor, CryptoStreamMode.Read))
{
int data;
while ((data = cs.ReadByte()) != -1)
{
fsOut.WriteByte((byte)data);
}
}
}
}
}
}
}
catch { throw; }
}
示例10: DecryptFile
internal static void DecryptFile(string inputFile, string outputFile, string password)
{
{
var UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
var fsCrypt = new FileStream(inputFile, FileMode.Open);
var RMCrypto = new AesManaged();
var cs = new CryptoStream(fsCrypt,
RMCrypto.CreateDecryptor(key, key),
CryptoStreamMode.Read);
var fsOut = new FileStream(outputFile, FileMode.Create);
int data;
while ((data = cs.ReadByte()) != -1)
fsOut.WriteByte((byte)data);
fsOut.Close();
cs.Close();
fsCrypt.Close();
}
}
示例11: DecryptFile
public static void DecryptFile(string inputFile, string outputFile, string password)
{
{
//string password = @"myKey123"; // Your Key Here
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateDecryptor(key, key),
CryptoStreamMode.Read);
FileStream fsOut = new FileStream(outputFile, FileMode.Create);
int data;
while ((data = cs.ReadByte()) != -1)
fsOut.WriteByte((byte) data);
fsOut.Close();
cs.Close();
fsCrypt.Close();
}
}
示例12: DecryptFile
public static void DecryptFile(string sInputFilename,
string sOutputFilename,
string sKey)
{
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
FileStream fsread = new FileStream(sInputFilename,
FileMode.Open,
FileAccess.Read);
ICryptoTransform desdecrypt = DES.CreateDecryptor();
CryptoStream cryptostreamDecr = new CryptoStream(fsread,
desdecrypt,
CryptoStreamMode.Read);
FileStream fswrite = new FileStream(sOutputFilename,
FileMode.Create,
FileAccess.Write);
int b;
while ((b = cryptostreamDecr.ReadByte()) >= 0)
{
fswrite.WriteByte((byte) b);
}
fswrite.Close();
cryptostreamDecr.Close();
fsread.Close();
}
示例13: Decrypt
public static byte[] Decrypt(SymmetricAlgorithm algorithm,byte[] data)
{
using (MemoryStream memory = new MemoryStream(data))
{
using (CryptoStream decrypt = new CryptoStream(memory, algorithm.CreateDecryptor(algorithm.Key, algorithm.IV), CryptoStreamMode.Read))
{
var result = new List<byte>();
var ibyte = decrypt.ReadByte();
while(ibyte > -1)
{
result.Add((byte)ibyte);
ibyte = decrypt.ReadByte();
}
return result.ToArray();
}
}
}
示例14: ComputeSha1
public static String ComputeSha1(string fileName)
{
using (var sha1Managed = new SHA1Managed())
using (Stream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
using (Stream sha1Stream = new CryptoStream(fileStream, sha1Managed, CryptoStreamMode.Read))
{
while (sha1Stream.ReadByte() != -1);
return Convert.ToBase64String(sha1Managed.Hash);
}
}
示例15: Byte2String
public static string Byte2String(CryptoStream stream)
{
string x= "";
int i = 0;
do
{
i = stream.ReadByte();
if (i != -1) x += ((char)i);
} while (i != -1);
return (x);
}