zoukankan      html  css  js  c++  java
  • PDBSample.cs

    using System;
    using System.IO;
    using System.Security.Cryptography;
    using System.Text;

    namespace APress.DotNetSecurity.Chapter2.PDBSample
    {
     class PDBSampleTester
     {
      static void Main(string[] args)
      {
       try
       {
        Console.WriteLine("Creating the salt...");
        RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
        byte[] rngData = new byte[8];
        rng.GetBytes(rngData);
        Console.WriteLine("Salt value is " + ArrayToHexString(rngData));

        PasswordDeriveBytes pwdDerive = new PasswordDeriveBytes("SuperSecretPassword",
         rngData);

        Console.WriteLine("Creating the IV...");
        byte[] ivData = new byte[8];
        rng.GetBytes(ivData);
        Console.WriteLine("IV value is " + ArrayToHexString(ivData));

        Console.WriteLine("Deriving the RC2 key...");
        RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider();
        byte[] RC2Key =
         pwdDerive.CryptDeriveKey("RC2", "SHA", 128, ivData);

        rc2.Key = RC2Key;
        Console.WriteLine("Key value is " + ArrayToHexString(rc2.Key));
       }
       catch(CryptographicUnexpectedOperationException cuoe)
       {
        Console.WriteLine("CryptographicUnexpectedOperationException:  "
         + cuoe.Message);
        Console.WriteLine(cuoe.StackTrace);
       }
       catch(CryptographicException ce)
       {
        Console.WriteLine("CryptographicException:  " + ce.Message);
        Console.WriteLine(ce.StackTrace);
       }
       catch(Exception ge)
       {
        Console.WriteLine("Exception:  " + ge.GetType().Name + " " + ge.Message);
        Console.WriteLine(ge.StackTrace);
       }
       finally
       {
        Console.WriteLine("Press the return key to continue...");
        Console.Read();
       }
      }
      private static String ArrayToHexString(byte[] ByteData)
      {
       StringBuilder retVal = new StringBuilder();
       
       foreach(byte b in ByteData)
       {
        retVal.Append(b.ToString("X2"));
        retVal.Append(" ");
       }
       retVal.Remove(retVal.Length - 1, 1);

       return retVal.ToString();
      } 
     }
    }

  • 相关阅读:
    win7常用快捷键
    java中构造代码块、方法调用顺序问题
    eclipse项目改为maven项目导致svn无法比较历史数据的解决办法
    linux配置Anaconda python集成环境
    DataFrame对行列的基本操作实战
    驱动:电阻屏触摸芯片NS2009
    读书笔记:代码大全(第二版)
    资料:磁角度传感器芯片
    经验:FatFs文件系统实时写入
    笔记:CAN收发器-TJA1051T与TJA1051T/3调试总结
  • 原文地址:https://www.cnblogs.com/dushu/p/2511961.html
Copyright © 2011-2022 走看看