Download ROCKEY5 TIME USER GUIDE
Transcript
ROCKEY5 TIME USER GUIDE Objective: Generate RSA key pair Input parameters: wPubID [in]Public key ID wPriID [in]Private key ID wKeyBitLen [in]The length of RSA key (512/1024/2048) Note: Considering the encrypt strength and operational speed, the common length of RSA private key is 1024 bit. The different private key length maps to the related data check 6.4.11 and 6.4.12 for more detail. wPubID and wPriID must use unoccupied ID in the current directory. This function will create two new file. Return value: Success returns 0. Other return means failure. For more detail, check the error list in section 6.12. Example: char xdata plaintext[] = "HELLO"; BYTE xdata ciphertext[128]; BYTE xdata bRes = 0; WORD xdata wPubKeyFileID = 0x1002; //Public key ID WORD xdata wPriKeyFileID = 0x1004; //Private key ID WORD xdata wKeyLen = 1024; //RSA key length //Generate key bRes = _rsa_gen_key(wPubKeyFileID, wPriKeyFileID, wKeyLen); if(bRes != 0) { _set_response(1,&bRes); _exit(); } memset(ciphertext,0,128); //Assign 0 to cipher text //Copy HELLO” to cipher text //Set the first byte as 0 in case that the plain text is over key length. memcpy(ciphertext+1, plaintext, 6); //RSA encryption, the 128 bytes result is in cipher text bRes = _rsa_enc(RSA_CALC_PKCS | RSA_CALC_BIT_1024, wPubKeyFileID, 6, ciphertext); if(bRes != 0) { _set_response(1,&bRes); _exit(); } //RSA decrypts with length of 128 bytes. Copyright © Feitian Technologies Co. Ltd. Website: www.FTsafe.com 83