?? class1.cs
字號:
using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Text;
namespace sanpack_rsa_csclass
{
public class Sanpack_rsa
{
public static string s1;
public static string s2;
public static System.Collections.ArrayList charlist=new ArrayList();
public static System.Collections.ArrayList hextxtlist=new ArrayList();
public static System.Collections.ArrayList result_hexstrings=new ArrayList();
public static uint RSAstep;
public static uint RSAprimeplen1;
public static uint RSAprimeplen2;
[DllImport("sanpack_rsa.dll")]
public static extern string get_Version();
[DllImport("sanpack_rsa.dll")]
public static extern int refresh_RSA_san(string a,string b);
[DllImport("sanpack_rsa.dll")]
public static extern int start_RSA_san();
[DllImport("sanpack_rsa.dll")]
public static extern int finish_RSA_san();
[DllImport("sanpack_rsa.dll")]
public static extern int RSA_san_en(byte []b,uint n);
[DllImport("sanpack_rsa.dll")]
public static extern int RSA_san_en_byte(byte b);
[DllImport("sanpack_rsa.dll")]
public static extern int RSA_san_dn(byte []b,uint n);
[DllImport("sanpack_rsa.dll")]
public static extern int RSA_san_en_hexstring(string s);
[DllImport("sanpack_rsa.dll")]
public static extern int RSA_san_dn_hexstring(string s);
[DllImport("sanpack_rsa.dll")]
public static extern string get_p();
[DllImport("sanpack_rsa.dll")]
public static extern string get_q();
[DllImport("sanpack_rsa.dll")]
public static extern string get_n();
[DllImport("sanpack_rsa.dll")]
public static extern string get_e();
[DllImport("sanpack_rsa.dll")]
public static extern string get_d();
[DllImport("sanpack_rsa.dll")]
public static extern string get_result_string();
[DllImport("sanpack_rsa.dll")]
public static extern byte get_result_byte(uint i);
[DllImport("sanpack_rsa.dll")]
public static extern string get_result_hexstring();
[DllImport("sanpack_rsa.dll")]
public static extern string string2hexstring(string s);
[DllImport("sanpack_rsa.dll")]
public static extern int set_e_fromhexstring(string s);
[DllImport("sanpack_rsa.dll")]
public static extern int force_e(string s,uint l);
[DllImport("sanpack_rsa.dll")]
public static extern int force_d(string s,uint l);
[DllImport("sanpack_rsa.dll")]
public static extern int force_n(string s,uint l);
public static int GetRandomString()
{
Random rnd = new Random();
Byte[] b = new Byte[System.Math.Max(RSAprimeplen1,RSAprimeplen2)];
s1="";
s2="";
//next we'll produce 2 random string
//the string may have zero_code chars in it
//to prevent from cutting the string
//we change 00 into 41 in s1
// 00 into 42 in s2
//this work has been done in class RSA_san (sanpack_rsa.dll)
//while(s1.Length<35)
//{
for(int i=0;i<RSAprimeplen1;i++)
{
Byte tmp=System.Convert.ToByte(254.0*rnd.NextDouble());
if(tmp!=0)b[i]=tmp;else b[i]=1; //prevent zero_code chars here, but i dont know why it still appear@@
}
s1=Sanpack_rsa.FromASCIIByteArray(b);
//}
//while(s2.Length<35)
//{
for(int i=0;i<RSAprimeplen2;i++)
{
Byte tmp=System.Convert.ToByte(254.0*rnd.NextDouble());
if(tmp!=0)b[i]=tmp;else b[i]=1;
}
s2=Sanpack_rsa.FromASCIIByteArray(b);
//}
return 1;
}
public static string FromASCIIByteArray(byte[] characters)
{
ASCIIEncoding encoding = new ASCIIEncoding( );
string constructedString = encoding.GetString(characters);
return (constructedString);
}
public static string FromUnicodeByteArray(byte[] characters)
{
UnicodeEncoding encoding = new UnicodeEncoding( );
string constructedString = encoding.GetString(characters);
return (constructedString);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -