本文整理汇总了C#中System.Security.Cryptography.DSACryptoServiceProvider.ExportParameters方法的典型用法代码示例。如果您正苦于以下问题:C# DSACryptoServiceProvider.ExportParameters方法的具体用法?C# DSACryptoServiceProvider.ExportParameters怎么用?C# DSACryptoServiceProvider.ExportParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.DSACryptoServiceProvider
的用法示例。
在下文中一共展示了DSACryptoServiceProvider.ExportParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTest
public static void DoTest()
{
Console.WriteLine("使用 DSACryptoServiceProvider 类创建哈希值的数字签名,然后验证签名的例子!");
// 创建一个 DSA 算法的加密服务提供程序 (CSP) 实现的包装对象.
DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();
// 需要被签名的数据.
byte[] HashValue = { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 };
Console.WriteLine("初始 Hash 数据.");
ByteArrayOutput.Print(HashValue);
// 签名处理.
byte[] SignedHashValue = DSASignHash(HashValue, DSA.ExportParameters(true), "SHA1");
Console.WriteLine("使用私钥签名的数据.");
ByteArrayOutput.Print(SignedHashValue);
// 验证签名.
if (DSAVerifyHash(HashValue, SignedHashValue, DSA.ExportParameters(false), "SHA1"))
{
Console.WriteLine("使用公钥验证 签名是有效的!");
}
else
{
Console.WriteLine("使用公钥验证 签名无效.");
}
}
示例2: Main
static void Main(string[] args)
{
try
{
DSAParameters privatekeyinfo;
DSAParameters publickeyinfo;
//Create a new instance of DSACryptoServiceProvider to generate a new key pair.
using(DSACryptoServiceProvider DSA = new DSACryptoServiceProvider())
{
privatekeyinfo = DSA.ExportParameters(true);
publickeyinfo = DSA.ExportParameters(false);
byte[] HashValue;
using(FileStream fs = new FileStream(@"C:\Listener.txt", FileMode.Open, FileAccess.Read))
{
BinaryReader reader = new BinaryReader(fs);
HashValue = reader.ReadBytes((int)fs.Length);
//HashValue = new byte[fs.Length];
//fs.Read(HashValue, 0, (int)fs.Length);
//The hash value to sign
//HashValue = new byte[20]{
// 59, 4, 248, 102, 77, 97, 142, 201,
// 210, 12, 224, 93, 25, 41, 100, 197,
// 213, 134, 130, 135
// };
}
string OId = CryptoConfig.MapNameToOID("SHA1");
//The value to hold the signed value.
byte[] SignedHashValue = DSASignHash(HashValue, privatekeyinfo, OId);
//Verify the hash and display the results.
bool verified = DSAVerifyHash(HashValue, SignedHashValue, publickeyinfo, "SHA1");
if(verified)
{
Console.WriteLine("The hash value was verified.");
}
else
{
Console.WriteLine("The hash value was not verified.");
}
}
Console.ReadKey();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
示例3: TestMethodSendPrivateMessage
public void TestMethodSendPrivateMessage()
{
ASCIIEncoding encoding = new ASCIIEncoding();
DSACryptoServiceProvider mycryptoC = new DSACryptoServiceProvider();
DSAParameters publickeyC = mycryptoC.ExportParameters(false);
DSACryptoServiceProvider mycryptoW = new DSACryptoServiceProvider();
DSAParameters publickeyW = mycryptoW.ExportParameters(false);
byte[] hashC = mycryptoC.SignData(encoding.GetBytes("Cuddy"));
byte[] hashW = mycryptoW.SignData(encoding.GetBytes("Wilson"));
ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();
a.Register("Cuddy", "iluvhouse", hashC, publickeyC.Counter, publickeyC.G, publickeyC.J, publickeyC.P, publickeyC.Q, publickeyC.Seed, publickeyC.X, publickeyC.Y);
a.Register("Wilson", "ihatehouse", hashW, publickeyW.Counter, publickeyW.G, publickeyW.J, publickeyW.P, publickeyW.Q, publickeyW.Seed, publickeyW.X, publickeyW.Y);
string message = "je suis jalouse de Cameron";
byte[] messagesigned = mycryptoC.SignData(encoding.GetBytes(message));
Assert.AreEqual(true,a.SendPrivateMessage("Cuddy", "Wilson", message, messagesigned));
Assert.AreEqual(false, a.SendPrivateMessage("Cuddy", "Foreman", message, messagesigned));
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\Message_serialization.xml");
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\User_serialization.xml");
}
示例4: TestMethodReceivePrivateMessage
public void TestMethodReceivePrivateMessage()
{
ASCIIEncoding encoding = new ASCIIEncoding();
DSACryptoServiceProvider mycryptoC = new DSACryptoServiceProvider();
DSAParameters publickeyC = mycryptoC.ExportParameters(false);
DSACryptoServiceProvider mycryptoW = new DSACryptoServiceProvider();
DSAParameters publickeyW = mycryptoW.ExportParameters(false);
byte[] hashC = mycryptoC.SignData(encoding.GetBytes("Cuddy"));
byte[] hashW = mycryptoW.SignData(encoding.GetBytes("Wilson"));
ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();
a.Register("Cuddy", "iluvhouse", hashC, publickeyC.Counter, publickeyC.G, publickeyC.J, publickeyC.P, publickeyC.Q, publickeyC.Seed, publickeyC.X, publickeyC.Y);
a.Register("Wilson", "ihatehouse", hashW, publickeyW.Counter, publickeyW.G, publickeyW.J, publickeyW.P, publickeyW.Q, publickeyW.Seed, publickeyW.X, publickeyW.Y);
string message = "je suis jalouse de Cameron";
byte[] messagesigned = mycryptoC.SignData(encoding.GetBytes(message));
a.SendPrivateMessage("Cuddy", "Wilson", message, messagesigned);
UnitTest.ServiceReference1.Message[] b = a.ReceivePrivateMessage("Wilson", hashW);
Assert.AreEqual("Cuddy", b[0].Auteur); //j'avoue les test sont moisi... mais je voulais juste verifier si le retour par une classe implemente dans le webservice etait possible
Assert.AreEqual("je suis jalouse de Cameron", b[0].Text);
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\Message_serialization.xml");
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\User_serialization.xml");
}
示例5: DigitalSignatureAlgorithm_compare_parameters_generation_with_original_Pidgin_OffTheRecord_data
public void DigitalSignatureAlgorithm_compare_parameters_generation_with_original_Pidgin_OffTheRecord_data()
{
// Arrange
const string p =
"AEC0FBB4CEA96EF8BDD0E91D1BA2F6641B6535CBDA8D739CC2898FE7B472865AB60AD2B1BAA2368603C7439E63BC2F2F33D422E70173F70DB738DF5979EAEAF3CAC343CBF711960E16786703C80DF0734D8330DC955DA84B521DAB5C729202F1244D805E6BF2CC7A7142CAD74BE5FFFC14B9CCB6CABB7DB10A8F2DDB4E82383F";
const string q = "A2A2BC20E2D94C44C63608479C79068CE7914EF3";
const string g =
"69B9FC5A73F3F6EA3A86F8FA3A203F42DACDC3A1516002025E5765A9DCB975F348ACBBA2116230E19CE3FC5256546FD168A2940809BDA8655771967E9CD90AF44D2C20F97F448494213A775E23607F33C255A9A74E2A5FC7B4D50BAD024D7EFAC282E67332D51A5F69239011FE058D7E75E97A788FBD5B3BAD796B2C6D8C6C3E";
const string y =
"9931144F3059D92FCB2AAC03B130DAE43ED1EF30AA2F0E670C3974C3E80C7110D1A60210F92479D7F640C20E1F16E01B4A72FF8D45443B01EBE2D67DF49791CAC6191B159AC39446EB6A2EA597B6B678CC3157AECEAB12A804CF0772068A942EC819138EDD6005620FE746522FF408BBC8211ABD9D6016AA46EEC87F3F04CFA4";
const string x = "48BFDA215C31A9F0B226B3DB11F862450A0F30DA"; /* private key */
// Act
var param = new DSAParameters();
param.X = General.StringToByteArray(x);
param.P = General.StringToByteArray(p);
param.Q = General.StringToByteArray(q);
param.G = General.StringToByteArray(g);
param.Y = General.StringToByteArray(y);
var dsa = new DSACryptoServiceProvider(1024);
dsa.ImportParameters(param);
DSAParameters output = dsa.ExportParameters(true);
// Assert
param.X.SequenceEqual(output.X).Should().BeTrue();
param.P.SequenceEqual(output.P).Should().BeTrue();
param.Q.SequenceEqual(output.Q).Should().BeTrue();
param.G.SequenceEqual(output.G).Should().BeTrue();
param.Y.SequenceEqual(output.Y).Should().BeTrue();
}
示例6: init
public void init(int key_size)
{
// KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
// keyGen.initialize(key_size, new SecureRandom());
// KeyPair pair = keyGen.generateKeyPair();
// PublicKey pubKey=pair.getPublic();
// PrivateKey prvKey=pair.getPrivate();
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(key_size);
DSAParameters DSAKeyInfo = dsa.ExportParameters(true);
// x=((DSAPrivateKey)prvKey).getX().toByteArray();
// y=((DSAPublicKey)pubKey).getY().toByteArray();
//
// DSAParams _params=((DSAKey)prvKey).getParams();
// p=_params.getP().toByteArray();
// q=_params.getQ().toByteArray();
// g=_params.getG().toByteArray();
x = DSAKeyInfo.X;
y = DSAKeyInfo.Y;
p = DSAKeyInfo.P;
q = DSAKeyInfo.Q;
g = DSAKeyInfo.G;
}
示例7: Enregister
private void Enregister()
{
mycrypto = new DSACryptoServiceProvider();
ASCIIEncoding encoding = new ASCIIEncoding();
_publicKey = mycrypto.ExportParameters(false);
byte[] tab = encoding.GetBytes(_pseudo);
byte[] hash = mycrypto.SignData(tab);
_myServer.ReceiveKey(tab, hash, _publicKey);
}
示例8: init
public void init(int key_size)
{
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(key_size);
DSAParameters DSAKeyInfo = dsa.ExportParameters(true);
m_x = DSAKeyInfo.X;
m_y = DSAKeyInfo.Y;
m_p = DSAKeyInfo.P;
m_q = DSAKeyInfo.Q;
m_g = DSAKeyInfo.G;
}
示例9: EncodePublicKey
public void EncodePublicKey(IPublicKey publicKey, ByteBuf buffer)
{
var dsa = new DSACryptoServiceProvider();
var dsap = dsa.ExportParameters(false);
var rsa = new RSACryptoServiceProvider();
var rsap = rsa.ExportParameters(false);
}
示例10: TestMethodCHangeNick
public void TestMethodCHangeNick()
{
DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider();
DSAParameters Publickey = mycrypto.ExportParameters(false);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] hash = mycrypto.SignData(encoding.GetBytes("Cuddy"));
ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();
a.Register("Cuddy", "passbidon", hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y);
Assert.AreEqual(true, a.ChangeNick("Cuddy", "MissC", mycrypto.SignData(encoding.GetBytes("MissC"))));
hash = mycrypto.SignData(encoding.GetBytes("MissC"));
Assert.AreEqual(true, a.LogIn("MissC", "passbidon", hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));
}
示例11: PrivateKey
internal PrivateKey(DSAParameters dsaParameters)
{
privateKey = dsaParameters;
var dsa = new DSACryptoServiceProvider(1024);
dsa.ImportParameters(privateKey);
PublicKey = dsa.ExportParameters(false);
PublicKeyAsMPI = MultiPrecisionInteger.ByteArrayToMpi(PublicKey.P)
.Concat(MultiPrecisionInteger.ByteArrayToMpi(PublicKey.Q))
.Concat(MultiPrecisionInteger.ByteArrayToMpi(PublicKey.G))
.Concat(MultiPrecisionInteger.ByteArrayToMpi(PublicKey.Y))
.ToArray();
}
示例12: GenerateKeyPair
public bool GenerateKeyPair(string pubPath, string privPath)
{
try
{
using (DSACryptoServiceProvider dsaProvider = new DSACryptoServiceProvider())
{
DSAParameters publicKey = dsaProvider.ExportParameters(false);//pub
var binformt = new BinaryFormatter();
using (var fs = new FileStream(pubPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
{
//binformt.Serialize(fs, publicKey.Counter);
binformt.Serialize(fs, publicKey.Q);
binformt.Serialize(fs, publicKey.Seed);
binformt.Serialize(fs, publicKey.G);
binformt.Serialize(fs, publicKey.P);
binformt.Serialize(fs, publicKey.Counter);
binformt.Serialize(fs, publicKey.Y);
//binformt.Serialize(fs, publicKey.X);
binformt.Serialize(fs, publicKey.J);
fs.Close();
}
//File.WriteAllBytes(pubPath, memoryStream.GetBuffer());
DSAParameters privateKey = dsaProvider.ExportParameters(true);//generate private key
var binformt1 = new BinaryFormatter();
//var memoryStream1 = new MemoryStream();
using (var fs = new FileStream(privPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
{
binformt.Serialize(fs, privateKey.Q);
binformt.Serialize(fs, privateKey.Seed);
binformt.Serialize(fs, privateKey.G);
binformt.Serialize(fs, privateKey.P);
binformt.Serialize(fs, privateKey.Counter);
binformt.Serialize(fs, privateKey.Y);
binformt.Serialize(fs, privateKey.X);
binformt.Serialize(fs, privateKey.J);
fs.Close();
}
//File.WriteAllBytes(privPath, memoryStream1.GetBuffer());
//File.WriteAllBytes(privPath, keyData);
}
}
catch (Exception ex)
{
return false;
}
return true;
}
示例13: TestMethodSerialization
public void TestMethodSerialization()
{
//on simule l'ajout d'auteur
User aut1 = new User("Toto", "mypass1");
User aut2 = new User("JC", "mypass2");
User aut3 = new User("Max", "mypass3");
User aut4 = new User("Titi", "clearstream");
User aut5 = new User("Toadd", "serie");
DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider();
DSAParameters key = mycrypto.ExportParameters(false);
aut1.Publickey = key;
aut2.Publickey = key;
aut3.Publickey = key;
aut4.Publickey = key;
aut5.Publickey = key;
Message mess1 = new Message(aut1.Login, "Coucou ca va?");
Message mess2 = new Message(aut2.Login, "oue et toi?");
Message mess3 = new Message(aut3.Login, "tranquille!");
Message mess4 = new Message(aut1.Login, "ca va ca va");
Message mess5 = new Message(aut5.Login, "Test fifi");
Message mess6 = new Message(aut5.Login, "MessagePrive: cool ma poule?");
aut1.AddPrivateMessage(mess6);
//on simule
Chat toTest = new Chat();
Chat toOut = new Chat();
toTest.AddUser(aut1);
toTest.AddUser(aut2);
toTest.AddUser(aut3);
toTest.AddUser(aut4);
toTest.AddMessage(mess1);
toTest.AddMessage(mess2);
toTest.AddMessage(mess3);
toTest.AddMessage(mess4);
toTest.Serialiser();
toOut.Deserialiser();
toOut.AddUser(aut5);
toOut.AddMessage(mess5);
toOut.Serialiser();
//l'analyse du test se fera manuellement dans le fichier de sortie
}
示例14: PrincipalForm
/// <summary>
/// Constructeur par defaut
/// </summary>
public PrincipalForm()
{
InitializeComponent();
SaveForm param_fenetre = Serializer.DeserialiserFenetre();
if (param_fenetre != null)
{
this.Size = new System.Drawing.Size(param_fenetre.Weightform, param_fenetre.Heightform);
this.splitContainer1.SplitterDistance = param_fenetre.Splitterdistance;
this.Location = new System.Drawing.Point(param_fenetre.LocalisationX, param_fenetre.LocalisationY);
}
//initialisation de liaison avec le service
client = new ServeurChat.ServeurChatSoapClient();
//generation des clé pour la session qui va etre lance
crypto = new DSACryptoServiceProvider();
securitykey = crypto.ExportParameters(false);
connected = false;
}
示例15: TestMethodRegisterAndLogin
public void TestMethodRegisterAndLogin()
{
DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider();
DSAParameters Publickey = mycrypto.ExportParameters(false);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] hash = mycrypto.SignData(encoding.GetBytes("Cuddy"));
ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();
Assert.AreEqual(true, a.Register("Cuddy", "passbidon",hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));
Assert.AreEqual(false, a.Register("Cuddy", "rate",hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));
Assert.AreEqual(true,a.LogIn("Cuddy", "passbidon",hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));
Assert.AreEqual(false, a.LogIn("Cuddy", "badpass",hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));
//remise a zero du serveur
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\Message_serialization.xml");
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\User_serialization.xml");
}