EldoS | Feel safer!

Software components for data protection, secure storage and transfer

About TElX509Certificate_obj.SaveKeyToBufferPEM method some questions

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#5579
Posted: 03/24/2008 02:09:21
by  xu cong
We using:
byte[] pemT;
string key = keypwd.Value;
TElX509Certificate_obj.SaveKeyToBufferPEM(out pemT, key);
string Pem = SBUtils.Unit.UTF8ToStr(pemT);
TextArea1.Value = Pem;

The TElX509Certificate_obj.SaveKeyToBufferPEM method cannot realize the wish function.
Only return:
"-----BEGIN RSA PRIVATE KEY-----\n\n-----END RSA PRIVATE KEY-----\n";
#5580
Posted: 03/24/2008 02:43:47
by Eugene Mayevski (EldoS Corp.)

What are the values of certificate's PrivateKeyExists and PrivateKeyExtractable properties?


Sincerely yours
Eugene Mayevski
#5582
Posted: 03/24/2008 03:44:05
by  xu cong
Public key :
-----BEGIN CERTIFICATE-----
MIIDBTCCAm6gAwIBAgIDBm+gMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDYxMTAxMjEwNzA0WhcNMDcxMTAyMjEwNzA0
WjCBjzELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNoYW5naGFpMREwDwYDVQQHEwhT
aGFuZ2hhaTElMCMGA1UEChMcRWR3YXJkIEtlbGxlciAoU2hhbmdoYWkpIEx0ZDET
MBEGA1UECxMKSGVhbHRoY2FyZTEeMBwGA1UEAxMVd3d3LmhlYWx0aGNhcmUubmV0
LmNuMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCaciAmuJzx+k+azdExeMEJ
bGVHdU7nw+rzWQL7UzgnCnkhcHX8hH31MGEoDHbG7I3ldNSxRG3ID2/CNwsG3AQ6
+fB8SsR/88OrDasgcK6Yea6m55uNWxPYDxpawSk429a3NlvFZz/woTa5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KwJAMR5C1eRfEOxu/6FU7rDl4/VQ3ILn
NOlwqihWdVNmO+aNfZXgOUlT9EXPdOe7kFMUuXt1+0+hNSIPMtfVRikkgQJBAKzJ
cyKDPA60MX1iji0/H8FpJUA3ppiJn60A/wyRrvHMKa/RlZPGWDJL3/JOgo5GAJv3
HFlJMhzhjeQiZK43ryMCQGf2TRaaB6R4+c92053ukSEIRm22SCsL+8lplTjclTmM
KjhT+pigMH1n/CBpL6kQ/6TIAXgf+8HC+DG3Ecq0Br8=
-----END RSA PRIVATE KEY-----
#5583
Posted: 03/24/2008 03:55:58
by Ken Ivanov (EldoS Corp.)

Not sure if I understood what you wished to say by posting certificate and private key here. Have you succeeded in saving the private key?
#5584
Posted: 03/24/2008 05:18:34
by  xu cong
We want .pfx the file conversion .pem form private key and the .cer form certificate.
Here has section of codes :
#5585
Posted: 03/24/2008 05:19:42
by  xu cong
[code]public void upload_PFX()
{
try
{
// Get the data

string pwd = PKCSpwd.Value;
string key = keypwd.Value;
hidd_PKCSpwd.Value = pwd;
hidd_keypwd.Value = key;
DateTime date = DateTime.Now;
string date_ = date.ToString("yyyyMMddHHmmss");
string yyyy = date_.Substring(0, 4);
string MM = date_.Substring(4, 2);
string dd = date_.Substring(6, 2);
string HH = date_.Substring(8, 2);
string mm = date_.Substring(10, 2);
string ss = date_.Substring(12, 2);
string fullname = File1.PostedFile.FileName; //获取文件在客户端的完整路径和文件名
string name = fullname.Substring(fullname.LastIndexOf("\\") + 1); // 字符串截取函数取得文件名
string[] namearr1 = name.Split('.');
name = yyyy + MM + dd + HH + mm + ss;
hidd_name.Value = name;
string type = File1.PostedFile.ContentType; // 字符串截取函数取得文件后缀名
if (type == "application/x-pkcs12" || type == "PFX")// 判断是否为图片
{
File1.PostedFile.SaveAs(Server.MapPath("../upload") + "\\" + name + ".pfx"); //上传到服务器UP目录
}
else
{
Response.Write("alert('文件格式错误!');");
return;
}

System.IO.FileStream FS = File.OpenRead(Server.MapPath("../upload") + "\\" + name + ".pfx");
TELX509.LoadFromStreamPFX(FS, pwd, 0);
byte[] pemT;
byte[] cerT;


TELX509.SaveKeyToBufferPEM(out pemT, key);
string Pem = SBUtils.Unit.UTF8ToStr(pemT);
TextArea1.Value = Pem;
if (Pem == "" || Pem=="-----BEGIN RSA PRIVATE KEY-----\n\n-----END RSA PRIVATE KEY-----\n")
{
Response.Write("alert('您的PKCS密码或PKCS文件有误!');");
return;
}

TELX509.SaveToBufferPEM(out cerT, "");
string Cer = SBUtils.Unit.UTF8ToStr(cerT);
TextArea2.Value = Cer;

div_display.InnerHtml = "document.getElementById(\"div_down\").style.display=\"\"";
FS.Close();
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
#5586
Posted: 03/24/2008 06:23:20
by Ken Ivanov (EldoS Corp.)

It is likely that the certificate is not loaded correctly from PFX. Remember that you need to check the return value:

int res = TELX509.LoadFromStreamPFX(FS, pwd, 0);
if (res == 0) {
// the certificate has been loaded correctly
} else {
// load failed
}
#5593
Posted: 03/24/2008 20:14:38
by  xu cong
TELX509.LoadFromStreamPFX­(FS, pwd, 0) return 0;
But TELX509.SaveKeyToBufferPE­M(out pemT, key) method just the same return
"-----BEGIN RSA PRIVATE KEY-----\n\n-----END RSA PRIVATE KEY-----\n";
#5595
Posted: 03/25/2008 01:03:06
by  xu cong
this is my code:
Code
string key = Password1.Value;
            byte[] pemT;
            byte[] cerT;
            string Pem = "";
            Pem = TextArea1.Value;
            pemT = SBUtils.Unit.StrToUTF8(Pem);
            int rep = TELX509.LoadKeyFromBufferPEM(pemT, key);
            if (rep != 0)
            {
                Response.Write("<script>alert('Your information makes a mistake!');</script>");
                return;
            }          
            
            bool reT = TELX509.SaveKeyToBuffer(out cerT);            
            string Cer = SBUtils.Unit.UTF8ToStr(cerT);

Why "TELX509.SaveKeyToBuffer(out cerT);" return false ?
#5600
Posted: 03/25/2008 02:37:25
by Ken Ivanov (EldoS Corp.)

1) Does TElX509Certificate.SaveToBufferPEM work?
2) What are the values of PrivateKeyExists and PrivateKeyExtractable properties before SaveKeyToBufferPEM is called?
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 5373 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!