-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRSA_test.c
executable file
·70 lines (61 loc) · 3.03 KB
/
RSA_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*********************************************************************************
name: RSA_test.C
author: yuxiang
date: 2011.9.21
note: 本文件用于测试RSA.C中的加密算法。
note: 本程序使用的是RSA 512位加密算法。默认为密钥N长度为64个字节,以字节为单元存储;
若有变动,请及时修改RSA.h中的NSIZE与UNIT_BITS。
**********************************************************************************/
#include<stdio.h>
#include<string.h>
#include "RSA.h"
void RSA_test(void)
{
unsigned char n_byte[64] =
{0x91,0xab,0xb4,0x0a,0xad,0x2c,0xf3,0x3b,0x8c,0x5a,0x09,0x2b,0xdc,0xd1,0x63,0x46,0xcc,0xcf,0xeb,0x2a,0x22,0x95,0x78,0xe1,0x82,0x45,0xb1,0xed,0xed,0x98,0x5b,0xbc,0xcc,0x75,0x54,0x3e,0x95,0x3b,0xa0,0x12,0x2b,0x37,0xdc,0x43,0xd0,0x42,0x67,0x3d,0xaf,0x48,0x47,0x9b,0xdd,0xb7,0xd4,0xce,0x0a,0x4b,0x9b,0x8a,0xb2,0x9e,0xeb,0x47};
unsigned char d_byte[3] = {0x01, 0x00, 0x01};
unsigned char crypted_byte[64] =
{0x32,0xE2,0xc4,0x9f,0x90,0x32,0xb1,0xb1,0x0a,0x7f,0xf5,0x8e,0xab,0x92,0x4a,0xe5,0x45,0x4a,0x25,0x57,0xfb,0x34,0x5d,0x05,0xb5,0xb1,0xaa,0xad,0x64,0xdb,0x2b,0xed,0xB3,0x38,0xb4,0x2c,0x77,0x58,0xc5,0x23,0xc7,0xf7,0xaa,0xc5,0x97,0x69,0x07,0x7a,0x78,0x6a,0x64,0xfa,0x52,0x8c,0x71,0xa3,0x1f,0xd8,0x12,0x7b,0x52,0x83,0x04,0x1e};
unsigned char abstract[32]=
{0x8e,0xdf,0x84,0x69,0x72,0x4f,0x58,0x20,0x5a,0x08,0x99,0xab,0x2d,0x27,0x01,0x6b,0x0a,0x3f,0xad,0xd9,0x19,0x8c,0x43,0xe0,0xd1,0x61,0x38,0x60,0x96,0x9a,0xd6,0xe9};
unsigned char e_byte[64]=
{0xe1,0x7a,0x92,0x7f,0x30,0x35,0xb2,0x9c,0x54,0xb1,0xec,0x33,0xf4,0x4d,0xc2,0x65,0x14,0x6e,0x56,0xf7,0xa8,0x33,0xe6,0x50,0x5a,0x4b,0xf5,0x52,0xb4,0xce,0x3a,0x1d,0x04,0x8d,0x4f,0xdb,0x0a,0x77,0xf0,0x3f,0x77,0xd3,0x61,0xa2,0x35,0x09,0xe4,0x47,0xf7,0xd2,0x77,0xf3,0x3e,0xe9,0xd9,0xab,0x82,0xf6,0x09,0x5b,0xb6,0x7f,0x16,0x35};
int i = 0;
//取密文密钥长度
U16 N_len=sizeof(n_byte);
//解密
unsigned char decrypted_byte[32] ;
U16 d_len =sizeof(d_byte);
U16 ecrypted_len =sizeof(crypted_byte);
U16 decrypted_len=sizeof(decrypted_byte);
//加密
unsigned char ecrypted_byte1[64] ;
U16 e_len =sizeof(e_byte);
U16 abstract_len1=sizeof(abstract);
U16 ecr_len1 =sizeof(ecrypted_byte1);
memset(decrypted_byte,0,32);
memset(ecrypted_byte1,0,64);
////////////////解密///////////////////
printf("原密文\n");
for( i=63;i>=0;i--)
printf("%x,",crypted_byte[i]);
printf("\n**********\n");
//Decrypt(decrypted_byte,crypted_byte,d_byte,n_byte,decrypted_len,ecrypted_len,d_len,N_len);
if(Decrypt(decrypted_byte,crypted_byte,d_byte,n_byte,decrypted_len,ecrypted_len,d_len,N_len)<0)
printf("解密失败!\n");
printf("解密完成!明文:\n");
for( i=31;i>=0;i--)
printf("%x,",decrypted_byte[i]);
printf("\n**********\n");
//////////////////加密//////////////////
printf("原摘要:\n");
for( i=31;i>=0;i--)
printf("%x,",abstract[i]);
printf("\n长度%d\n",abstract_len1);
printf("\n**********\n");
printf("对原摘要加密,密文\n");
Ecrypt(ecrypted_byte1,abstract,e_byte,n_byte,ecr_len1,abstract_len1,e_len,N_len);
for( i=63;i>=0;i--)
printf("%x,",ecrypted_byte1[i]);
printf("\n**********\n");
}