1int main(int,argc,char argv) | 2 | 3WSADATA wsaData; | 4SCOKET client; | 5RSA ; | 6serv.sin_family=AF_INET; | 7serv.sin_port=htons(port); | 8serv.sin_addr.S_un.S_addr=inet_addr(''127.0.0.1''); | 9client=socket(AF_INET,SOCK_STREAM,0); | 10connect(client,(struct )&serv,sizeof | (serv)); | 11Gene_Rand; | 12Comp_Str; | 13memcpy(plaitxt_A_E,Str_Id,1024); | 14public_Encrypt(plaitxt_A_E); | 15strcpy(Cipher_buf,(const )cipher); | 16iSend=send(client,Cipher,sizeof(Cipher),0); | 17iLen=recv(client,(char cipher,sizeof(cipher),0); | 18memcpy(Tcipher_Na_Nb,cipher_Na_Nb,1024); | 19Private_Dencrypt_Na_Nb(R,Tciper_Na_Nb); | 20memcpy(plaitxt_Nb,StrNb,1024); | 21Public_Encrypt_Nb(plaitxt_Nb); | 22strcpy(Cipher,(const)cipher); | 23iSend=send(client,Cipher,sizeof(Cipher),0); | | 25int Gene_Rand | 26 | 27BIGNUM ; | 28int ret,bits=128; | 29char ; | 30n=BN_new; | 31ret=BN_pseudo_rand(n,bits,1,1); | 32sn=BN_bn2dec(n); | 33strcpy(RandNum,sn); | 34return 0; | | 36int Com_Str | 37 | 38strcat(Str_Id,RandNum); | 39strcat(Str_Id, ''A''); | 40return 0; | | 42int Public_Encrypt(unsigned chars) | 43 | 44RSA ; | 45int ret,flent,len; | 46BIGNUM ,; | 47bnn=BN_new; | 48bne=BN_new; | 49ret=BN_dec2bn(&bnn,strn); | 50ret=BN_dec2bn(&bnn,stre); | 51r=RSA_new; | 52r->n=bnn; | 53r->e=bne; | 54flen=RSA_size(r); | 55len=RSA_public_encrypt(flen,s,cipher_A_E,r,3); | 56return 0; | | 58int Private_Dencrypt_Na_Nb(RSA ,unsigned chars) | 59 | 60int len,flen; | 61flen=RSA_size(r); | 62len=RSA_private_decrypt(flen,s,plaitxt_Na_Nb, r,3); | 63return 0; | | 65int StrDivNb(char str) | 66 | 67int k=0,i=0,j=0; | 68int strlen=0; | 69int Publi_Encrypt_Nb(usigned chars) | 70 | 71RSA ; | 72int ret,flen,len; | 73BIGNUM ,; | 74bnn=BN_new; | 75bne=BN_new; | 76ret=BN_dec2bn(&bnn,strn); | 77ret=BN_dec2bn(&bne,strn); | 78r=RSA_new; | 79r->n=bnn; | 80r->e=bne; | 81flen=RSA_size(r); | 82len=RSA_public_encrypt(flen,s,cipher_Nb,r,3); | 83return 0; | |
|