请教Sha1WithRSA签名的问题,急!
我使用的是D2010,openssl是1.0.0.7(其他版本也试过),libeay32.pas是从网上下载的0.9.6b
按照百度搜索的文章所说,在libeay32.pas中添加
procedure EVP_MD_CTX_init(ctx: pEVP_MD_CTX); cdecl;
procedure EVP_MD_CTX_cleanup(ctx: pEVP_MD_CTX); cdecl;
function RSA_sign(rsatype: integer; m: PCharacter; m_length: integer;
sigbuf: PCharacter; siglen: Cardinal; rsa: pRSA): integer; cdecl;
procedure EVP_MD_CTX_init; external LIBEAY_DLL_NAME;
procedure EVP_MD_CTX_cleanup; external LIBEAY_DLL_NAME;
function RSA_sign; external LIBEAY_DLL_NAME;
key文件是用openssl工具生成的,可是签名却总是报内存错误
以下是详细代码,请做过的给指点以下,
uses
libeay32, EncdDecd;
function LoadPrivateKey(filename: AnsiString): PEVP_PKEY;
var
bp: PBIO;
A, pkey: PEVP_PKEY;
begin
A := nil;
bp := BIO_new(BIO_s_file());
BIO_read_filename(bp, PAnsiChar(filename));
pkey := PEM_read_bio_PrivateKey(bp, A, nil, NIL);
BIO_free(bp);
Result := pkey;
end;
function Sign(filename, msg: AnsiString): string;
var
ctx: EVP_MD_CTX;
buf_in: PAnsiChar;
m_len, outl: cardinal;
pkey: PEVP_PKEY;
m, buf_out: array [0 .. 1024] of AnsiChar;
p: array [0 .. 255] of AnsiChar;
i: Integer;
begin
buf_out := '';
if filename = '' then
begin
Result := '';
Exit;
end;
ZeroMemory(@m, SizeOf(m));
ZeroMemory(@buf_out, SizeOf(buf_out));
pkey := LoadPrivateKey(filename);
buf_in := PAnsiChar(msg);
EVP_MD_CTX_init(@ctx); // 初始化
EVP_SignInit(@ctx, EVP_sha1());
EVP_SignUpdate(@ctx, buf_in, Length(buf_in));
EVP_DigestFinal(@ctx, m, m_len);
RSA_sign(EVP_sha1()._type, m, m_len, buf_out, outl, pkey.pkey.rsa); //<---------------此处报错
{
---------------------------
Project1
---------------------------
Access violation at address 67A93071 in module 'libeay32.dll'. Read of address EF96BD97.
---------------------------
确定
---------------------------
}
EVP_MD_CTX_cleanup(@ctx);
Result := EncodeString(StrPas(buf_out));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OpenSSL_add_all_algorithms;
Sign('d:\rsa_private_key.pem', '123456');
end;
按照百度搜索的文章所说,在libeay32.pas中添加
procedure EVP_MD_CTX_init(ctx: pEVP_MD_CTX); cdecl;
procedure EVP_MD_CTX_cleanup(ctx: pEVP_MD_CTX); cdecl;
function RSA_sign(rsatype: integer; m: PCharacter; m_length: integer;
sigbuf: PCharacter; siglen: Cardinal; rsa: pRSA): integer; cdecl;
procedure EVP_MD_CTX_init; external LIBEAY_DLL_NAME;
procedure EVP_MD_CTX_cleanup; external LIBEAY_DLL_NAME;
function RSA_sign; external LIBEAY_DLL_NAME;
key文件是用openssl工具生成的,可是签名却总是报内存错误
以下是详细代码,请做过的给指点以下,
uses
libeay32, EncdDecd;
function LoadPrivateKey(filename: AnsiString): PEVP_PKEY;
var
bp: PBIO;
A, pkey: PEVP_PKEY;
begin
A := nil;
bp := BIO_new(BIO_s_file());
BIO_read_filename(bp, PAnsiChar(filename));
pkey := PEM_read_bio_PrivateKey(bp, A, nil, NIL);
BIO_free(bp);
Result := pkey;
end;
function Sign(filename, msg: AnsiString): string;
var
ctx: EVP_MD_CTX;
buf_in: PAnsiChar;
m_len, outl: cardinal;
pkey: PEVP_PKEY;
m, buf_out: array [0 .. 1024] of AnsiChar;
p: array [0 .. 255] of AnsiChar;
i: Integer;
begin
buf_out := '';
if filename = '' then
begin
Result := '';
Exit;
end;
ZeroMemory(@m, SizeOf(m));
ZeroMemory(@buf_out, SizeOf(buf_out));
pkey := LoadPrivateKey(filename);
buf_in := PAnsiChar(msg);
EVP_MD_CTX_init(@ctx); // 初始化
EVP_SignInit(@ctx, EVP_sha1());
EVP_SignUpdate(@ctx, buf_in, Length(buf_in));
EVP_DigestFinal(@ctx, m, m_len);
RSA_sign(EVP_sha1()._type, m, m_len, buf_out, outl, pkey.pkey.rsa); //<---------------此处报错
{
---------------------------
Project1
---------------------------
Access violation at address 67A93071 in module 'libeay32.dll'. Read of address EF96BD97.
---------------------------
确定
---------------------------
}
EVP_MD_CTX_cleanup(@ctx);
Result := EncodeString(StrPas(buf_out));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OpenSSL_add_all_algorithms;
Sign('d:\rsa_private_key.pem', '123456');
end;
...全文
相关推荐
linux c 使用openssl实现SHA1WithRSA实现,签名,验签
linux c 使用openssl实现SHA1WithRSA实现,签名,验签
支付宝_签名_SHA256WithRsa签名_SHA1WithRSA签名delphi源码.rar
支付宝签名,SHA256WithRsa签名,SHA1WithRSA签名, delph所有源码,有需要的朋友绝对值这个分数!
C# SHA1withRsa的各种操作
C# SHA1withRsa的各种操作:加密解密,加签验签
C# SHA1withRsa签名函数,加解密 封装类
支付宝验名验证函数可参考此代码。 SHA1withRsa的各种操作:加密解密,加签验签。 C#源码可编译。签名调用方法:SHA1WithRSA.sign(str, key, "UTF-8");
sha1withrsa算法 华为sha256withrsa算法
ANDROID SDK接入的华为c++验证算法 sha1withrsa算法 华为sha256withrsa算法


Windows SDK/API

