Skip to content

Commit 2167dda

Browse files
authored
Create demo_sm2_public_key_digest.c (#1430)
1 parent 352ddc1 commit 2167dda

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
10+
#include <stdio.h>
11+
#include <string.h>
12+
#include <stdlib.h>
13+
#include <gmssl/mem.h>
14+
#include <gmssl/sm2.h>
15+
#include <gmssl/sm3.h>
16+
17+
int main(void){
18+
SM2_KEY sm2_key;
19+
uint8_t dgst[32];
20+
int i;
21+
22+
printf("Read SM2 public key file (PEM) from stdin ...\n");
23+
24+
if (sm2_public_key_info_from_pem(&sm2_key, stdin) != 1) {
25+
fprintf(stderr, "error\n");
26+
return 1;
27+
}
28+
29+
if (sm2_public_key_digest(&sm2_key, dgst) != 1) {
30+
fprintf(stderr, "error\n");
31+
return 1;
32+
}
33+
34+
for (i = 0; i < sizeof(dgst); i++) {
35+
printf("%02x", dgst[i]);
36+
}
37+
printf("\n");
38+
39+
gmssl_secure_clear(&sm2_key, sizeof(sm2_key));
40+
return 0;
41+
}

0 commit comments

Comments
 (0)