D crypto api

292 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
292
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

D crypto api

  1. 1. DEKART CRYPTOGRAPHY API 8 2005
  2. 2. 822 9 4 E+22:? 13*5672/ .317=8)/ 3<).+2)7 A52*C)? (; ./)@7 ,>:*+ F), ;D31,H)D ; DekartCryptoAPI. I=);31)/., 2739D31)6+, .<=+;3-2+, )2A3=6+C),.DSSSCT File : DCryptoAPI.doc Ref : DCSPPG0011 Revision:1.0 Page: 2 Copyright © Dekart S.R.L (www.dekart.com ) – 2005 This document shall not be disclosed to a third party without prior written consent of Dekart S.R.L. ()*+*+, -+./0 1+22343 13*5672/+ 27 6387/ 9:/0 ;3.<=3)>;7172+ ; *+*3? 9: /3 2) 9:@3 A3=67 ) *+*)6) 9: /3 2) 9:@3 .=71./;+6) 97> <).06722343 =+>=7B72), ;@+17@0C+ +;/3=.*)D <=+;. / 01 2 2 1 345 6172 .
  3. 3. ; 1 162 61. <8=<8>?<@? 8= 8A;BC@..................................................................................42. ;AE@? /F?G?<@H......................................................................................................43. ;I@/8<@? JK<CL@M A@AN@;B?C@ DSVIEW.DLL............................4 3.1. JK<CL@H GETREQUESTCERTDATA ................................................................................................................4 3.2. JK<CL@H GETPUBLICKEYCRTDATA ..............................................................................................................6 3.3. JK<CL@H GETSIGNATUREDATA .................................................................ERROR! BOOKMARK NOT DEFINED. 3.4. JK<CL@H GETCOMMONDATA ....................................................................ERROR! BOOKMARK NOT DEFINED.4. I @N;?<@H .............................................. ERROR! BOOKMARK NOT DEFINED. 4.1. C;G] ;^@A;C .............................................................................................ERROR! BOOKMARK NOT DEFINED. 4.2. I @_? F]=;F8 JK<CL@M _;GKNH @= I ;` 8__] (BORLAND C++ V.5.02)..... ERROR! BOOKMARK NOT DEFINED. 4.3. I; HG;C =8I;N<?<@H C8 B;>C@ 8KB?<B@J@L@ ;F8<<;`; ;BC ]B;`; CNe>8 G8<<]_@, I;NK>?<<]_@ / I;_;Ege DOSDVIEW.EXE ................................................ERROR! BOOKMARK NOT DEFINED. 4.4. I; HG;C =8I;N<?<@H J; _KNH 8 "DISPOZITIE DE PLATA TREZORERIALA (ELECTRONICA)" G8<<]_@, I;NK>?<<]_@ / I;_;Ege DOSDVIEW.EXE.............................ERROR! BOOKMARK NOT DEFINED. 4.5. I; HG;C =8I;N<?<@H J; _KNH 8 "DISPOZITIE DE PLATA (ELECTRONICA)" G8<<]_@, I;NK>?<<]_@ / I;_;Ege DOSDVIEW.EXE ................................................ERROR! BOOKMARK NOT DEFINED.DSSSCT File : DCryptoAPI.doc Ref : DCSPPG0011 Revision:1.0 Page: 3 Copyright © Dekart S.R.L (www.dekart.com ) – 2005 This document shall not be disclosed to a third party without prior written consent of Dekart S.R.L. ()*+*+, -+./0 1+22343 13*5672/+ 27 6387/ 9:/0 ;3.<=3)>;7172+ ; *+*3? 9: /3 2) 9:@3 A3=67 ) *+*)6) 9: /3 2) 9:@3 .=71./;+6) 97> <).06722343 =+>=7B72), ;@+17@0C+ +;/3=.*)D <=+;. / 01 2 2 1 345 6172 .
  4. 4. 1. < 52 k62 6 5 3 Dekart CryptoAPI <=712+>2+-723 1@, <=713./+;@72), *327-2365 <3@0>3;+/7@O 52)A)C)=3;+22343 )2/7=A7?.+ =+93/: . Cryptographic Service Provider. . 2. ;3m 6 6 62 4 Dekart CryptoAPI ;*@O-+7/ ; .79, .@715OH)7 A52*C)): 1. S+>3;:7 *=)</34=+A)-7.*)7 A52*C)): A52*C)) B)A=3;+2),/=+.B)A=3;:;+2), 1+22:D; A52*C)) D7B)=3;+2), ) <3@5-72), C)A=3;3? <31<).) 1+22:D; A52*C)) )2)C)+@)>+C)) *=)</3<=3;+?17=+ ) =+93/: . <3@5-722:6 *32/7*./36; A52*C)) 4727=+C)) *@O-7?; A52*C)) 39672+ *@O-+6). 2. V52*C)) *31)=3;+2),/17*31)=3;+2),. I31 *31)=3;+2)76 ; 1+2236 .@5-+7 <31=+>567;+7/., <3@5-72)7 2+ ;:D317 )2A3=6+C)), *31)=3;+223? ; A3=6+/7 ASN.1 (Abstract Syntax Notation One). 3. V52*C)) =+93/: . .7=/)A)*+/+6). 4. ]:.3*35=3;27;:7 A52*C)) 39=+93/*) *=)</34=+A)-7.*)D .339H72)?. 5. ()>*35=3;27;:7 A52*C)) 39=+93/*) *=)</34=+A)-7.*)D .339H72)?.. (739D31)637 393=513;+2)7: • ^36<0O/7= IBM PC (486 ) ;:B7). (739D31)637 <=34=+66237 397.<7-72)7: • a<7=+C)322+, .)./76+ MS Windows. 3. ; 2 6 n 2 9 o Dekart CryptoAPI 3.1. J 2 9 4 CryptEnumProviders !": CryptEnumProviders $" !": I3>;3@,7/ <3@5-)/0 <3@2:? <7=7-720 ./=3*3;:D )672 *=)</3<=3;+?17=3;. %! & (!(: #include “dsview.h” int CryptEnumProviders(dwIndex, NULL, 0, &dwType, NULL, &cbName))); )*+, -" , -": ReqFile - 5*+>+/7@0 2+ ./=3*5, .317=8+H5O )6, A+?@+ >+<=3.+ ) <5/0 * 2765; DSSSCT File : DCryptoAPI.doc Ref : DCSPPG0011 Revision:1.0 Page: 4 Copyright © Dekart S.R.L (www.dekart.com ) – 2005 This document shall not be disclosed to a third party without prior written consent of Dekart S.R.L. ()*+*+, -+./0 1+22343 13*5672/+ 27 6387/ 9:/0 ;3.<=3)>;7172+ ; *+*3? 9: /3 2) 9:@3 A3=67 ) *+*)6) 9: /3 2) 9:@3 .=71./;+6) 97> <).06722343 =+>=7B72), ;@+17@0C+ +;/3=.*)D <=+;. / 01 2 2 1 345 6172 .
  5. 5. PKReqData - 5*+>+/7@0 2+ ./=5*/5=5 TPKReq, .317=8+H5O .@715OH)7 <3@,: User_ID - 6+..); .)6;3@3;, .317=8+H)? )172/)A)*+/3= <3@0>3;+/7@,; User_eID - 6+..); .)6;3@3;, .317=8+H)? )6, <3@0>3;+/7@, (=+.B)=72)7 )172/)A)*+/3=+ <3@0>3;+/7@,); User_PKey - 6+..); .)6;3@3;, .317=8+H)? 3/*=:/:? *@O- <3@0>3;+/7@, ; 31236 )> /=7D A3=6+/3;: 17.,/)-236 (DEC), B7./2+1C+/7=)-236 (HEX) )@) BASE64; ReqSign_r - 6+..); .)6;3@3;, .317=8+H)? >2+-72)7 r C)A=3;3? <31<).) >+<=3.+ 2+ .7=/)A)*+C)O 3/*=:/343 *@O-+ <3@0>3;+/7@, ; 31236 )> /=7D A3=6+/3;: 17.,/)-236 (DEC), B7./2+1C+/7=)-236 (HEX) )@) BASE64; ReqSign_s - 6+..); .)6;3@3;, .317=8+H)? >2+-72)7 s C)A=3;3? <31<).) >+<=3.+ 2+ .7=/)A)*+C)O 3/*=:/343 *@O-+ <3@0>3;+/7@, ; 31236 )> /=7D A3=6+/3;: 17.,/)-236 (DEC), B7./2+1C+/7=)-236 (HEX) )@) BASE64; OutBase – C7@37 -).@3 (3.23;+2)7 .)./76: .-).@72),), >+1+OH77 ;:D3123? A3=6+/ <=71./+;@72), C)A=3;:D 1+22:D. a23 6387/ 9:/0 =+;2:6 10 1@, DEC, 16 – 1@, HEX ) 64 – 1@, BASE64. I3 563@-+2)O m/3 >2+-72)7 =+;23 16.)-*+, -" , -": a/.5/./;5O/.)+ . / "0+" $" !": I=) 5.<7B236 >+;7=B72)) A52*C), ;3>;=+H+7/ 1. ] <=3/);236 .@5-+7 – *31 3B)9*) (.6. ^31: 3B)93* ; <.Error! Reference source not found.).1.!0". - + 23 4!! ! 5.+6. 00-DWORD dwIndex=0;DWORD dwType;DWORD cbName;LPTSTR pszName;while (CryptEnumProviders(dwIndex, NULL, 0, &dwType, NULL, &cbName)){ if (!cbName) break; if (!(pszName = (LPTSTR)LocalAlloc(LMEM_ZEROINIT, cbName))) return; if (!CryptEnumProviders(dwIndex++, NULL, 0, &dwType, pszName, &cbName)) { Error("CryptEnumProviders"); return; } std::cout<<"--------------------------------"<<std::endl; std::cout<<"Provider name: "<<pszName<<std::endl; std::cout<<"Provider type: "<<dwType<<std::endl; LocalFree(pszName);}DSSSCT File : DCryptoAPI.doc Ref : DCSPPG0011 Revision:1.0 Page: 5 Copyright © Dekart S.R.L (www.dekart.com ) – 2005 This document shall not be disclosed to a third party without prior written consent of Dekart S.R.L. ()*+*+, -+./0 1+22343 13*5672/+ 27 6387/ 9:/0 ;3.<=3)>;7172+ ; *+*3? 9: /3 2) 9:@3 A3=67 ) *+*)6) 9: /3 2) 9:@3 .=71./;+6) 97> <).06722343 =+>=7B72), ;@+17@0C+ +;/3=.*)D <=+;. / 01 2 2 1 345 6172 .
  6. 6. 3.2. J 2 9 4 CryptEncrypt !": CryptEncrypt $" !": I3>;3@,7/ <39@3-23 >+B)A=3;+/0 1+22:7 <3@0>3;+/7@,.%! & (!(: #include <wincrypt.h> BOOL CryptEncrypt(HCRYPTKEY hKey, HCRYPTHAS hHash, BOOL Final, DWORD dwFlags, BYTE* pbData, DWORD* pdwDataLen, DWORD dwBufLen);)*+, -" , -": hKey - HCRYPTKEY (17.*=)</3=, @34)-7.*)? 2367=), .;,>+22:? . .7..)322:6 *@O-36 , <=)672,76:6 1@, B)A=3;+2),. Final – <+=+67/=, .)42+@)>)=5OH)? 3 <3.@71276 9@3*7 B)A=576:D 1+22:D. dwBufLen – =+>67= ;D312343 95A7=+ 1+22:D. DwFlags – 27).<3@0>576:? <+=+67/=, 39:-23 5./+2+;@);+7/., ; 0. PbData - 5*+>+/7@0 2+ 6+..); ;D312:D 1+22:D.)-*+, -" , -": hHash – HCRYPTHAS (17.*=)</3=, @34)-7.*)? 2367=), .;,>+22:? . hash- >2+-72)76 B)A=576:D 1+22:D. PdwDataLen – =+>67= 1+22:D, ;3>;=+H+76:D A52*C)7?. PbData - 5*+>+/7@0 2+ 6+..); ;:D312:D 1+22:D.)+ . / "0+" $" !": I=) 5.<7B236 >+;7=B72)) A52*C), ;3>;=+H+7/ TRUE. ] <=3/);236 .@5-+7 – FALSE.1.!0". - + 23 4!! ! 5.+6. 00- HCRYPTPROV hProv; HCRYPTKEY hSessionKey; // @ABCDEFGE HAFIEHJIK HLGMIAMLANKOPELK if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { Error("CryptAcquireContext"); return; } std::cout << "Cryptographic provider initialized" << std::endl; // TEFELKUGV JEJJGAFFAWA HBXDK if (!CryptGenKey(hProv, CALG_RC4, CRYPT_ENCRYPT | CRYPT_DECRYPT, &hSessionKey)) { Error("CryptGenKey"); return; } std::cout << "Session key generated" << std::endl; // KFF]E PBV ^G_LANKFGVDSSSCT File : DCryptoAPI.doc Ref : DCSPPG0011 Revision:1.0 Page: 6 Copyright © Dekart S.R.L (www.dekart.com ) – 2005 This document shall not be disclosed to a third party without prior written consent of Dekart S.R.L. ()*+*+, -+./0 1+22343 13*5672/+ 27 6387/ 9:/0 ;3.<=3)>;7172+ ; *+*3? 9: /3 2) 9:@3 A3=67 ) *+*)6) 9: /3 2) 9:@3 .=71./;+6) 97> <).06722343 =+>=7B72), ;@+17@0C+ +;/3=.*)D <=+;. / 01 2 2 1 345 6172 .
  7. 7. char string[]="Test"; DWORD count=strlen(string); // bG_LANKFGE PKFF]c if (!CryptEncrypt(hSessionKey, 0, true, 0, (BYTE*)string, &count, strlen(string))) { Error("CryptEncrypt"); return; } std::cout << "Encryption completed" << std::endl; // fEJIAN]O N]NAP FK gHLKF std::cout << "Encrypted string: " << string << std::endl; 3.3. J 2 9 4 CryptExportKey !": CryptExportKey $" !": I3>;3@,7/ m*.<3=/)=3;+/0 .7..)322:7 *@O-) ;3 ;27B2)? 6+..); 1+22:D.%! & (!(: #include <wincrypt.h> BOOL CryptExportKey (HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType, DWORD dwFlags, BYTE* pdData, DWORD* pdwDataLen);)*+, -" , -": hKey - HCRYPTKEY (17.*=)</3=, @34)-7.*)? 2367=), .;,>+22:? . .7..)322:6 *@O-36, *3/3=:? 9517/ m*.<3=/)=3;+2. hExpKey – HCRYPTKEY (17.*=)</3=, @34)-7.*)? 2367=), .;,>+22:? . *@O-36, 2+ *3/3=36 9517/ >+B)A=3;+2 .7..)322:? *@O-. ] 93@0B)2./;7 .@5-+7; )2)C)+@)>)=57/., *32/7*./36 3/*=:/343 *@O-+ <3@5-+/7@,. DwFlags – 27).<3@0>576:? <+=+67/=, 39:-23 5./+2+;@);+7/., ; 0.)-*+, -" , -": hHash – HCRYPTHAS (17.*=)</3=, @34)-7.*)? 2367=), .;,>+22:? . hash- >2+-72)76 B)A=576:D 1+22:D. PdwDataLen – =+>67= 1+22:D, ;3>;=+H+76:D A52*C)7?. PdData - 5*+>+/7@0 2+ 6+..); ;:D312:D 1+22:D.)+ . / "0+" $" !": I=) 5.<7B236 >+;7=B72)) A52*C), ;3>;=+H+7/ TRUE. ] <=3/);236 .@5-+7 – FALSE.1.!0". - + 23 4!! ! 5.+6. 00- HCRYPTPROV hProv; HCRYPTKEY hKey, hPublicKey, hNewKey; // hFGUGKBGiKUGV HAFIEHJIK HLGMIAMLANKOPELK (J CHKiKFGEj GjEFG // HAFIEOFELK HBXDEO) if (!CryptAcquireContext(&hProv, "{EB57ED8A-CCCC-4bf5-8659-9DF2F05F24AD}", NULL, PROV_RSA_FULL, 0)) return;DSSSCT File : DCryptoAPI.doc Ref : DCSPPG0011 Revision:1.0 Page: 7 Copyright © Dekart S.R.L (www.dekart.com ) – 2005 This document shall not be disclosed to a third party without prior written consent of Dekart S.R.L. ()*+*+, -+./0 1+22343 13*5672/+ 27 6387/ 9:/0 ;3.<=3)>;7172+ ; *+*3? 9: /3 2) 9:@3 A3=67 ) *+*)6) 9: /3 2) 9:@3 .=71./;+6) 97> <).06722343 =+>=7B72), ;@+17@0C+ +;/3=.*)D <=+;. / 01 2 2 1 345 6172 .
  8. 8. std::cout << "Cryptographic provider initialized" << std::endl; // TEFELKUGV HBXDK PBV IEJIGLANKFGV if (!CryptGenKey(hProv, CALG_RC4, CRYPT_EXPORTABLE | CRYPT_ENCRYPT | CRYPT_DECRYPT, &hKey)) return; std::cout << "Session key generated" << std::endl; // @ABCDEFGE HBXDK PBV gHJMALIK HBXDK ^G_LANKFGV if (!CryptGetUserKey(hProv, AT_KEYEXCHANGE, &hPublicKey)) return; std::cout << "Public key is received" << std::endl; count = 0; // @ABCDEFGE LKijELK jKJJGNK, GJMABqiCEjAWA PBV gHJMALIK HBXDK if (!CryptExportKey(hKey, hPublicKey, SIMPLEBLOB, 0, NULL, &count)) return; // hFGUGKBGiKUGV jKJJGNK, GJMABqiCEjAWA PBV gHJMALIK HBXDK BYTE* data = static_cast<BYTE*>(malloc(count)); ZeroMemory(data, count); // sHJMALI HBXDK ^G_LANKFGV if (!CryptExportKey(hKey, hPublicKey, SIMPLEBLOB, 0, data, &count)) return; std::cout << "Keys export completed" << std::endl; . s.@) ;3>;=+H+76:7 1+22:7 6345/ 9:/0 @O9343 =+>67=+ (+ m/3 ;3>63823, ;710,.*+876, ; +@43=)/67 6387/ <=3).D31)/0 <=3./+, >+672+, *341+ 312+ 95*;+ *31)=57/.,-7/:=06, C)A=+6)), /3 =+93/+ . A52*C)7? .3./3)/ )> 1;5D m/+<3;. (+ <7=;36 m/+<7 ;A52*C)O <7=71+7/., 39H)? =+>67= ;D312:D 1+22:D ) NULL ; *+-7./;7 ..:@*) 2+ .+66+..); ;:D312:D 1+22:D. V52*C), ;3>;=+H+7/ 1@)25 ;:D312343 6+..);+ 1+22:D,<3@0>3;+/7@0 )2)C)+@)>)=57/ <+6,/0 2739D31)6343 =+>67=+ ), @)B0 >+/76, >+23;3 <7=71+7/A52*C)) ..:@*5 2+ m/3/ 6+..);.DSSSCT File : DCryptoAPI.doc Ref : DCSPPG0011 Revision:1.0 Page: 8 Copyright © Dekart S.R.L (www.dekart.com ) – 2005 This document shall not be disclosed to a third party without prior written consent of Dekart S.R.L. ()*+*+, -+./0 1+22343 13*5672/+ 27 6387/ 9:/0 ;3.<=3)>;7172+ ; *+*3? 9: /3 2) 9:@3 A3=67 ) *+*)6) 9: /3 2) 9:@3 .=71./;+6) 97> <).06722343 =+>=7B72), ;@+17@0C+ +;/3=.*)D <=+;. / 01 2 2 1 345 6172 .

×