How to subscribe to a blog from another site?
Using existing public/private keys in C#
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > .Net Development > Using existing public/private keys in C# 23 December 2009 06:58:21

  Top users: 
  Recent blog posts: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Модератор:

Using existing public/private keys in C#

Nate Swart 1 May 2003 18:46:59
 I'm trying to use existing public/private keys in C# and am getting
nowhere. I can create new keys in C#, save them, and re-import them
fine.

My old system is in Java, so I created some code to export the keys into
the XML format that C# expects. From what I've read, C# expects the keys
to be binary strings that have been BASE64 encoded. My Java code grabs
the key parameters in binary format, then encodes them and creates the
XML files. When I read the XML files into C#, it fails because of "Bad
Data".

Has anyone done this before, or able to see what I'm doing wrong?

Thanks!
-Nate


I've included (hopefully) all the relevant code/information below:



*******************­**** Stack Trace *******************­****

at
System.Security.Cry­ptography.DSACryptoS­erviceProvider._Impo­rtKey(IntPtr
hCSP, Int32 algid, DSACspObject data)
at
System.Security.Cry­ptography.DSACryptoS­erviceProvider.Impor­tParameters(D
SAParameters parameters)
at System.Security.Cry­ptography.DSA.FromXm­lString(String xmlString)
at VerifyLicense() in executioner.cs:line­ 111




*******************­**** C# Code *******************­****
StreamReader re = new StreamReader(keyStr­eam);
string xmlString = re.ReadToEnd();

// Everything looks fine when I pump the xmlString out to the console
Console.WriteLine(x­mlString);

DSACryptoServicePro­vider crypt = new DSACryptoServicePro­vider();

// Fails on this next line
crypt.FromXmlString­(xmlString);

Console.WriteLine(c­rypt.ToXmlString(tru­e));




*******************­**** Java Code *******************­****
for(int i=0; i<fileNames.length;­ i++)
{
KeyFactory keyFactory = KeyFactory.getInsta­nce( "DSA" );
DSAPrivateKey privateKey =
(DSAPrivateKey) keyFactory.generate­Private(
new PKCS8EncodedKeySpec­( loadProductKeyBytes­(fileNames[i],
"privatekey" ) ) );

DSAPublicKey publicKey =
(DSAPublicKey) keyFactory.generate­Public(
new X509EncodedKeySpec(­ loadProductKeyBytes­(fileNames[i],
"publickey" ) ) );

// Convert binary to Base64
BASE64Encoder e = new BASE64Encoder();
String sP = e.encodeBuffer(priv­ateKey.getParams().g­etP().toByteArray())­;
String sQ = e.encodeBuffer(priv­ateKey.getParams().g­etQ().toByteArray())­;
String sG = e.encodeBuffer(priv­ateKey.getParams().g­etG().toByteArray())­;
String sX = e.encodeBuffer(priv­ateKey.getX(­.toByte­Array()).trim();
String sY = e.encodeBuffer(publ­icKey.getY().toByteA­rray()).trim();

String finalOutput = "";
finalOutput += "<DSAKeyValue>";
finalOutput += "<P>";
finalOutput += sP;
finalOutput += "</p>";
finalOutput += "<Q>";
finalOutput += sQ;
finalOutput += "</Q>";
finalOutput += "<G>";
finalOutput += sG;
finalOutput += "</G>";
finalOutput += "<X>";
finalOutput += sX;
finalOutput += "</X>";
finalOutput += "<Y>";
finalOutput += sY;
finalOutput += "</Y>";
finalOutput += "</DSAKeyValue>";
// Write XML file
File outputFile = new File(newKeyPath + fileNames[i] + ".xml");
FileWriter out = new FileWriter(outputFi­le);
out.write(finalOutp­ut);
System.out.println(­finalOutput);
out.close();
}

private static byte[] loadProductKeyBytes­( String id, String keyType )
throws IOException
{
File keyFile = new File( keyPath, id + "." + keyType );
int fileLength = (int)keyFile.length­();
BufferedInputStream­ bis = new BufferedInputStream­(
new FileInputStream( keyFile ) );
byte[] bytes = new byte[fileLength];
bis.read( bytes, 0, bytes.length );
return bytes;
}

Add comment
SteveC 4 May 2003 02:42:03 permanent link ]
 I have used CAPICOM with public/private key pairs (enveloping and signing).
I generated the keys first with OpenSSL. But my client and server were both
Win32 apps, for Java I think there is one additional hoop you must jump
thru.

I think you will want to check out the CAPICOM e'list for info on using
CAPICOM, there are a lot of sharp guys who do nothing but this kind of
thing.

For 1.0 of the Framework, the WSDK has some additional key functionality so
you might not need CAPICOM (but I have not tried it yet). I don't know what
1.1 has yet.

hth

---orig

I'm trying to use existing public/private keys in C# and am getting
nowhere. I can create new keys in C#, save them, and re-import them
fine.
[snip]

Add comment
Robert Rolls 5 May 2003 01:30:22 permanent link ]
 http://discuss.micro­soft.com there is a CAPICOM and CAPI listserv
available.

-----Original Message-----
From: SteveC [mailto:stevec@ATOMIC9.NET]
Sent: Sunday, 4 May 2003 9:42 AM
To: ADVANCED-DOTNET@DIS­CUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] re Using existing public/private keys in C#

I have used CAPICOM with public/private key pairs (enveloping and
signing).
I generated the keys first with OpenSSL. But my client and server were
both
Win32 apps, for Java I think there is one additional hoop you must jump
thru.

I think you will want to check out the CAPICOM e'list for info on using
CAPICOM, there are a lot of sharp guys who do nothing but this kind of
thing.

For 1.0 of the Framework, the WSDK has some additional key functionality
so
you might not need CAPICOM (but I have not tried it yet). I don't know
what
1.1 has yet.

hth

---orig

I'm trying to use existing public/private keys in C# and am getting
nowhere. I can create new keys in C#, save them, and re-import them
fine.
[snip]

Add comment
Guest 23 December 2009 06:58:21 permanent link ]
 S11223J2 Currently, Timberland is one of the most famous Timberland Classic brands. Throughout the 1990s, the popularity of the Timberland Kids Boot reached an important point. Also, in that time, the company added more mens Timberland 6 Inch products and lines to its catalog. Now, the prestige as a Timberland custom boots brand with excellent products is unquestionable.
In preparation for the upcoming cold seasons, the company has launched its collection called Timberland Women's Boots, which is already available at the Timberland stores. http://www.timberla­nder.com/products_al­l.html
Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или законы РФ. Ваш ip-адрес записывается.


QAIX > .Net Development > Using existing public/private keys in C# 23 December 2009 06:58:21

see also:
substitute character in variable
Problems with CPAN
redirect path in log file
pass tests:
..
see also:
Welkome to me
The Recession and Market Research
*__*

  Copyright © 2001—2010 QAIX
Идея: Монашёв Михаил.
Авторами текстов, изображений и видео, размещённых на этой странице, являются пользователи сайта.
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Пишите нам на .
If you would like to report an abuse of our service, such as a spam message, please .
Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .