Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Openssl
提交
17287562
T
Third Party Openssl
项目概览
OpenHarmony
/
Third Party Openssl
大约 1 年 前同步成功
通知
9
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
17287562
编写于
4月 11, 2008
作者:
D
Dr. Stephen Henson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Detached encrypt/decrypt example, fix decrypt sample.
上级
a12a6b99
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
190 addition
and
4 deletion
+190
-4
demos/cms/cms_ddec.c
demos/cms/cms_ddec.c
+89
-0
demos/cms/cms_dec.c
demos/cms/cms_dec.c
+4
-4
demos/cms/cms_denc.c
demos/cms/cms_denc.c
+97
-0
未找到文件。
demos/cms/cms_ddec.c
0 → 100644
浏览文件 @
17287562
/* S/MIME detached data decrypt example: rarely done but
* should the need arise this is an example....
*/
#include <openssl/pem.h>
#include <openssl/cms.h>
#include <openssl/err.h>
int
main
(
int
argc
,
char
**
argv
)
{
BIO
*
in
=
NULL
,
*
out
=
NULL
,
*
tbio
=
NULL
,
*
dcont
=
NULL
;
X509
*
rcert
=
NULL
;
EVP_PKEY
*
rkey
=
NULL
;
CMS_ContentInfo
*
cms
=
NULL
;
int
ret
=
1
;
OpenSSL_add_all_algorithms
();
ERR_load_crypto_strings
();
/* Read in recipient certificate and private key */
tbio
=
BIO_new_file
(
"signer.pem"
,
"r"
);
if
(
!
tbio
)
goto
err
;
rcert
=
PEM_read_bio_X509
(
tbio
,
NULL
,
0
,
NULL
);
BIO_reset
(
tbio
);
rkey
=
PEM_read_bio_PrivateKey
(
tbio
,
NULL
,
0
,
NULL
);
if
(
!
rcert
||
!
rkey
)
goto
err
;
/* Open PEM file containing enveloped data */
in
=
BIO_new_file
(
"smencr.pem"
,
"r"
);
if
(
!
in
)
goto
err
;
/* Parse PEM content */
cms
=
PEM_read_bio_CMS
(
in
,
NULL
,
0
,
NULL
);
if
(
!
cms
)
goto
err
;
/* Open file containing detached content */
dcont
=
BIO_new_file
(
"smencr.out"
,
"rb"
);
if
(
!
in
)
goto
err
;
out
=
BIO_new_file
(
"encrout.txt"
,
"w"
);
if
(
!
out
)
goto
err
;
/* Decrypt S/MIME message */
if
(
!
CMS_decrypt
(
cms
,
rkey
,
rcert
,
dcont
,
out
,
0
))
goto
err
;
ret
=
0
;
err:
if
(
ret
)
{
fprintf
(
stderr
,
"Error Decrypting Data
\n
"
);
ERR_print_errors_fp
(
stderr
);
}
if
(
cms
)
CMS_ContentInfo_free
(
cms
);
if
(
rcert
)
X509_free
(
rcert
);
if
(
rkey
)
EVP_PKEY_free
(
rkey
);
if
(
in
)
BIO_free
(
in
);
if
(
out
)
BIO_free
(
out
);
if
(
tbio
)
BIO_free
(
tbio
);
if
(
dcont
)
BIO_free
(
dcont
);
return
ret
;
}
demos/cms/cms_dec.c
浏览文件 @
17287562
...
@@ -29,20 +29,20 @@ int main(int argc, char **argv)
...
@@ -29,20 +29,20 @@ int main(int argc, char **argv)
if
(
!
rcert
||
!
rkey
)
if
(
!
rcert
||
!
rkey
)
goto
err
;
goto
err
;
/* Open
content being signed
*/
/* Open
S/MIME message to decrypt
*/
in
=
BIO_new_file
(
"smencr.txt"
,
"r"
);
in
=
BIO_new_file
(
"smencr.txt"
,
"r"
);
if
(
!
in
)
if
(
!
in
)
goto
err
;
goto
err
;
/*
Sign content
*/
/*
Parse message
*/
cms
=
SMIME_read_CMS
(
in
,
NULL
);
cms
=
SMIME_read_CMS
(
in
,
NULL
);
if
(
!
cms
)
if
(
!
cms
)
goto
err
;
goto
err
;
out
=
BIO_new_file
(
"
encr
out.txt"
,
"w"
);
out
=
BIO_new_file
(
"
dec
out.txt"
,
"w"
);
if
(
!
out
)
if
(
!
out
)
goto
err
;
goto
err
;
...
@@ -56,7 +56,7 @@ int main(int argc, char **argv)
...
@@ -56,7 +56,7 @@ int main(int argc, char **argv)
if
(
ret
)
if
(
ret
)
{
{
fprintf
(
stderr
,
"Error
Sign
ing Data
\n
"
);
fprintf
(
stderr
,
"Error
Decrypt
ing Data
\n
"
);
ERR_print_errors_fp
(
stderr
);
ERR_print_errors_fp
(
stderr
);
}
}
...
...
demos/cms/cms_denc.c
0 → 100644
浏览文件 @
17287562
/* S/MIME detached data encrypt example: rarely done but
* should the need arise this is an example....
*/
#include <openssl/pem.h>
#include <openssl/cms.h>
#include <openssl/err.h>
int
main
(
int
argc
,
char
**
argv
)
{
BIO
*
in
=
NULL
,
*
out
=
NULL
,
*
tbio
=
NULL
,
*
dout
=
NULL
;
X509
*
rcert
=
NULL
;
STACK_OF
(
X509
)
*
recips
=
NULL
;
CMS_ContentInfo
*
cms
=
NULL
;
int
ret
=
1
;
int
flags
=
CMS_STREAM
|
CMS_DETACHED
;
OpenSSL_add_all_algorithms
();
ERR_load_crypto_strings
();
/* Read in recipient certificate */
tbio
=
BIO_new_file
(
"signer.pem"
,
"r"
);
if
(
!
tbio
)
goto
err
;
rcert
=
PEM_read_bio_X509
(
tbio
,
NULL
,
0
,
NULL
);
if
(
!
rcert
)
goto
err
;
/* Create recipient STACK and add recipient cert to it */
recips
=
sk_X509_new_null
();
if
(
!
recips
||
!
sk_X509_push
(
recips
,
rcert
))
goto
err
;
/* sk_X509_pop_free will free up recipient STACK and its contents
* so set rcert to NULL so it isn't freed up twice.
*/
rcert
=
NULL
;
/* Open content being encrypted */
in
=
BIO_new_file
(
"encr.txt"
,
"r"
);
dout
=
BIO_new_file
(
"smencr.out"
,
"wb"
);
if
(
!
in
)
goto
err
;
/* encrypt content */
cms
=
CMS_encrypt
(
recips
,
in
,
EVP_des_ede3_cbc
(),
flags
);
if
(
!
cms
)
goto
err
;
out
=
BIO_new_file
(
"smencr.pem"
,
"w"
);
if
(
!
out
)
goto
err
;
if
(
!
CMS_final
(
cms
,
in
,
dout
,
flags
))
goto
err
;
/* Write out CMS structure without content */
if
(
!
PEM_write_bio_CMS
(
out
,
cms
))
goto
err
;
ret
=
0
;
err:
if
(
ret
)
{
fprintf
(
stderr
,
"Error Encrypting Data
\n
"
);
ERR_print_errors_fp
(
stderr
);
}
if
(
cms
)
CMS_ContentInfo_free
(
cms
);
if
(
rcert
)
X509_free
(
rcert
);
if
(
recips
)
sk_X509_pop_free
(
recips
,
X509_free
);
if
(
in
)
BIO_free
(
in
);
if
(
out
)
BIO_free
(
out
);
if
(
dout
)
BIO_free
(
dout
);
if
(
tbio
)
BIO_free
(
tbio
);
return
ret
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录