Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
5f6d0ea2
T
Third Party Openssl
项目概览
OpenHarmony
/
Third Party Openssl
1 年多 前同步成功
通知
10
Star
18
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Openssl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5f6d0ea2
编写于
25年前
作者:
D
Dr. Stephen Henson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reformat and "modernise" the sign.c demo.
上级
5a2e24ba
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
25 deletion
+46
-25
CHANGES
CHANGES
+6
-0
demos/sign/sign.c
demos/sign/sign.c
+40
-25
未找到文件。
CHANGES
浏览文件 @
5f6d0ea2
...
...
@@ -5,6 +5,12 @@
Changes between 0.9.3a and 0.9.4
*) Fix demos/sign/sign.c: well there wasn't anything strictly speaking
wrong with it but it was very old and did things like calling
PEM_ASN1_read() directly and used MD5 for the hash not to mention some
unusual formatting.
[Steve Henson]
*) Fix demos/selfsign.c: it used obsolete and deleted functions, changed
to use the new extension code.
[Steve Henson]
...
...
This diff is collapsed.
Click to expand it.
demos/sign/sign.c
浏览文件 @
5f6d0ea2
...
...
@@ -61,6 +61,10 @@
/* converted to C - eay :-) */
/* reformated a bit and converted to use the more common functions: this was
* initially written at the dawn of time :-) - Steve.
*/
#include <stdio.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
...
...
@@ -90,49 +94,60 @@ int main ()
/* Read private key */
fp
=
fopen
(
keyfile
,
"r"
);
if
(
fp
==
NULL
)
exit
(
1
);
pkey
=
(
EVP_PKEY
*
)
PEM_ASN1_read
((
char
*
(
*
)())
d2i_PrivateKey
,
PEM_STRING_EVP_PKEY
,
fp
,
NULL
,
NULL
);
if
(
pkey
==
NULL
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
fp
=
fopen
(
keyfile
,
"r"
);
if
(
fp
==
NULL
)
exit
(
1
);
pkey
=
PEM_read_PrivateKey
(
fp
,
NULL
,
NULL
);
fclose
(
fp
);
if
(
pkey
==
NULL
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
/* Do the signature */
EVP_SignInit
(
&
md_ctx
,
EVP_
md5
());
EVP_SignInit
(
&
md_ctx
,
EVP_
sha1
());
EVP_SignUpdate
(
&
md_ctx
,
data
,
strlen
(
data
));
sig_len
=
sizeof
(
sig_buf
);
err
=
EVP_SignFinal
(
&
md_ctx
,
sig_buf
,
&
sig_len
,
pkey
);
if
(
err
!=
1
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
err
=
EVP_SignFinal
(
&
md_ctx
,
sig_buf
,
&
sig_len
,
pkey
);
if
(
err
!=
1
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
EVP_PKEY_free
(
pkey
);
/* Read public key */
fp
=
fopen
(
certfile
,
"r"
);
if
(
fp
==
NULL
)
exit
(
1
);
x509
=
(
X509
*
)
PEM_ASN1_read
((
char
*
(
*
)())
d2i_X509
,
PEM_STRING_X509
,
fp
,
NULL
,
NULL
);
if
(
x509
==
NULL
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
fp
=
fopen
(
certfile
,
"r"
);
if
(
fp
==
NULL
)
exit
(
1
);
x509
=
PEM_read_X509
(
fp
,
NULL
,
NULL
);
fclose
(
fp
);
if
(
x509
==
NULL
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
/* Get public key - eay */
pkey
=
X509_extract_key
(
x509
);
if
(
pkey
==
NULL
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
pkey
=
X509_get_pubkey
(
x509
);
if
(
pkey
==
NULL
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
/* Verify the signature */
EVP_VerifyInit
(
&
md_ctx
,
EVP_
md5
());
EVP_VerifyInit
(
&
md_ctx
,
EVP_
sha1
());
EVP_VerifyUpdate
(
&
md_ctx
,
data
,
strlen
((
char
*
)
data
));
err
=
EVP_VerifyFinal
(
&
md_ctx
,
sig_buf
,
sig_len
,
pkey
);
if
(
err
!=
1
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
err
=
EVP_VerifyFinal
(
&
md_ctx
,
sig_buf
,
sig_len
,
pkey
);
EVP_PKEY_free
(
pkey
);
if
(
err
!=
1
)
{
ERR_print_errors_fp
(
stderr
);
exit
(
1
);
}
printf
(
"Signature Verified Ok.
\n
"
);
return
(
0
);
}
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部