RSA AsymmetricAlgorithm lost feature

G

Guest

FromXmlString and ToXmlString (RSA AsymmetricAlgorithm) has gone from Beta 2
compact framework.

It was on working fine on beta 1.

My company is having SOA implementation that use classic shacking hands
(Sending the public key, encrypt the symetric key, and decrypt it back at the
client side), know that this feature is lost we cannot do it with beta 2.

Fearther more we having encrypt configuration that should be readable from
the client and from the server (because maintainence issue), we used to
export the server configuration key to the client secure storage, but this
scenario is no aplicative with out the option of importing and exporting keys.

So has you see it’s a greet lost for us, can you do something about it?

We realy don’t want to move back to .NETCF it’s seem wrong to handle the API
directly.

What is your suggestion?

Bnaya Eshet C.T.O Wise Mobility.
 
S

Sergey Bogdanov

Did you consider to use
OpenNETCF.Security.Cryptograph­y.RSACryptoServiceProvider instead?

or you can extend it by porting these two methods from Full Framework
something like this (should work but not tested):

public class RSAExtender
{
RSA _rsa;

public RSAExtender(RSA rsa)
{
_rsa = rsa;
}

public void FromXmlString(string xmlString)
{
RSAParameters p;
if (xmlString == null) throw new
ArgumentNullException("xmlString");

p = new RSAParameters();
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);

XmlNode modulus = doc.SelectSingleNode("//Modulus");
if (modulus == null) throw new CryptographicException();
p.Modulus = Convert.FromBase64String(modulus.InnerText);

XmlNode exponent = doc.SelectSingleNode("//Exponent");
if (modulus == null) throw new CryptographicException();
p.Exponent = Convert.FromBase64String(exponent.InnerText);

XmlNode pNode = doc.SelectSingleNode("//P");
if (pNode != null)
p.P = Convert.FromBase64String(pNode.InnerText);

XmlNode qNode = doc.SelectSingleNode("//Q");
if (qNode != null)
p.Q = Convert.FromBase64String(qNode.InnerText);

XmlNode dpNode = doc.SelectSingleNode("//DP");
if (dpNode != null)
p.DP = Convert.FromBase64String(dpNode.InnerText);

XmlNode dqNode = doc.SelectSingleNode("//DQ");
if (dqNode != null)
p.DQ = Convert.FromBase64String(dqNode.InnerText);

XmlNode inverseQNode = doc.SelectSingleNode("//InverseQ");
if (inverseQNode != null)
p.InverseQ = Convert.FromBase64String(inverseQNode.InnerText);

XmlNode dNode = doc.SelectSingleNode("//D");
if (dNode != null)
p.D = Convert.FromBase64String(dNode.InnerText);

_rsa.ImportParameters(p);
}

public string ToXmlString(bool includePrivateParameters)
{
RSAParameters p = _rsa.ExportParameters(includePrivateParameters);
StringBuilder sb = new StringBuilder();

sb.Append("<RSAKeyValue>");
sb.Append("<Modulus>" + Convert.ToBase64String(p.Modulus) +
"</Modulus>");
sb.Append("<Exponent>" + Convert.ToBase64String(p.Exponent) +
"</Exponent>");

if (includePrivateParameters)
{
sb.Append("<P>" + Convert.ToBase64String(p.P) + "</P>");
sb.Append("<Q>" + Convert.ToBase64String(p.Q) + "</Q>");
sb.Append("<DP>" + Convert.ToBase64String(p.DP) + "</DP>");
sb.Append("<DQ>" + Convert.ToBase64String(p.DQ) + "</DQ>");
sb.Append("<InverseQ>" + Convert.ToBase64String(p.InverseQ)
+ "</InverseQ>");
sb.Append("<D>" + Convert.ToBase64String(p.D) + "</D>");
}

sb.Append("</RSAKeyValue>");
return sb.ToString();
}


}
 
G

Guest

TNX i will try it
i also tring the import and export blob.

Bnaya Eshet C.T.O Wise Mobility

Sergey Bogdanov said:
Did you consider to use
OpenNETCF.Security.Cryptograph­y.RSACryptoServiceProvider instead?

or you can extend it by porting these two methods from Full Framework
something like this (should work but not tested):

public class RSAExtender
{
RSA _rsa;

public RSAExtender(RSA rsa)
{
_rsa = rsa;
}

public void FromXmlString(string xmlString)
{
RSAParameters p;
if (xmlString == null) throw new
ArgumentNullException("xmlString");

p = new RSAParameters();
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);

XmlNode modulus = doc.SelectSingleNode("//Modulus");
if (modulus == null) throw new CryptographicException();
p.Modulus = Convert.FromBase64String(modulus.InnerText);

XmlNode exponent = doc.SelectSingleNode("//Exponent");
if (modulus == null) throw new CryptographicException();
p.Exponent = Convert.FromBase64String(exponent.InnerText);

XmlNode pNode = doc.SelectSingleNode("//P");
if (pNode != null)
p.P = Convert.FromBase64String(pNode.InnerText);

XmlNode qNode = doc.SelectSingleNode("//Q");
if (qNode != null)
p.Q = Convert.FromBase64String(qNode.InnerText);

XmlNode dpNode = doc.SelectSingleNode("//DP");
if (dpNode != null)
p.DP = Convert.FromBase64String(dpNode.InnerText);

XmlNode dqNode = doc.SelectSingleNode("//DQ");
if (dqNode != null)
p.DQ = Convert.FromBase64String(dqNode.InnerText);

XmlNode inverseQNode = doc.SelectSingleNode("//InverseQ");
if (inverseQNode != null)
p.InverseQ = Convert.FromBase64String(inverseQNode.InnerText);

XmlNode dNode = doc.SelectSingleNode("//D");
if (dNode != null)
p.D = Convert.FromBase64String(dNode.InnerText);

_rsa.ImportParameters(p);
}

public string ToXmlString(bool includePrivateParameters)
{
RSAParameters p = _rsa.ExportParameters(includePrivateParameters);
StringBuilder sb = new StringBuilder();

sb.Append("<RSAKeyValue>");
sb.Append("<Modulus>" + Convert.ToBase64String(p.Modulus) +
"</Modulus>");
sb.Append("<Exponent>" + Convert.ToBase64String(p.Exponent) +
"</Exponent>");

if (includePrivateParameters)
{
sb.Append("<P>" + Convert.ToBase64String(p.P) + "</P>");
sb.Append("<Q>" + Convert.ToBase64String(p.Q) + "</Q>");
sb.Append("<DP>" + Convert.ToBase64String(p.DP) + "</DP>");
sb.Append("<DQ>" + Convert.ToBase64String(p.DQ) + "</DQ>");
sb.Append("<InverseQ>" + Convert.ToBase64String(p.InverseQ)
+ "</InverseQ>");
sb.Append("<D>" + Convert.ToBase64String(p.D) + "</D>");
}

sb.Append("</RSAKeyValue>");
return sb.ToString();
}


}




--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com


Bnaya said:
FromXmlString and ToXmlString (RSA AsymmetricAlgorithm) has gone from Beta 2
compact framework.

It was on working fine on beta 1.

My company is having SOA implementation that use classic shacking hands
(Sending the public key, encrypt the symetric key, and decrypt it back at the
client side), know that this feature is lost we cannot do it with beta 2.

Fearther more we having encrypt configuration that should be readable from
the client and from the server (because maintainence issue), we used to
export the server configuration key to the client secure storage, but this
scenario is no aplicative with out the option of importing and exporting keys.

So has you see it’s a greet lost for us, can you do something about it?

We realy don’t want to move back to .NETCF it’s seem wrong to handle the API
directly.

What is your suggestion?

Bnaya Eshet C.T.O Wise Mobility.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top