Abstract:
Disclosed is an implementation method for driving of software and hardware supporting OpenSC. The method is implemented by middleware invoking an interface function, and comprises invocation of a function for initializing an interface, invocation of functions for establishing an encrypted communications environment, selecting a file interface, and selecting a file to operate, invocation of a function for setting a safe environment interface, and invocation of functions for building an APDU for setting a safe environment and setting a safe environment and a signature interface by sending the APDU, and building of a signed APDU and execution, by sending the APDU, of a signature operation on an original text to be signed.

Description:
[0001]    This application claims priority to Chinese patent application, titled “IMPLEMENTATION METHOD FOR DRIVING OF SOFTWARE AND HARDWARE SUPPORTING OPENS C” with Application Number of 201310520252.2 and filed with the Chinese Patent Office on Oct. 29, 2013, which is hereby incorporated by reference in its entirety. 
       FIELD OF THE INVENTION 
       [0002]    The present application relates to information security field, more particularly to an implementation method for driving of software and hardware supporting OpenSC. 
       BACKGROUND OF THE INVENTION 
       [0003]    OpenSC is a smart card project with open source, which is similar to middleware, and provides a set of drive interfaces which is convenient for respective manufacturers to add supportive devices of their own. 
         [0004]    At present, smart card devices based on identity authentication is widely used. How to realize supporting smart card device based on OpenSC becomes a difficult technical problem which a middleware developer is eager to solve. 
       SUMMARY OF THE INVENTION 
       [0005]    In order to overcome defection in the prior art, the present application provides an implementation method for driving of software and hardware supporting OpenSC. 
         [0006]    The technical solution applied to the present application is an implementation method for driving of software and hardware supporting OpenSC, which is implemented by that a middleware invokes an interface function. The method includes: 
         [0007]    building cipher text communication environment according to a communication key type of a card in a case that an initializing interface function is invoked, setting a key digit number supported by the card and returning an initialized result; 
         [0008]    performing an operation of selecting a file according to attribution of a first structure in a selecting a file interface function in a case that the selecting a file interface function is invoked, returning a result of the operation of the selecting the file; the result of the operation of the selecting the file contains file controlling information in a case that the operation of selecting the file is successful; 
         [0009]    obtaining key file attribution of the file controlling information according to a second parameter of the setting a security environment interface function in a case that a setting a security environment interface function is invoked, building an Application Protocol Data Unit (APDU) for setting a security environment according to the key file attribution, setting a security environment by transmitting the APDU for setting a security environment and returning a result of the setting; 
         [0010]    obtaining original data to be signed and length of the original data according to a second parameter and a third parameter of a signature interface function in a case that the signature interface function is invoked, building signed APDU based on the original data to be signed and the length of the original data, performing a signature operation on the original data to be signed by transmitting the signed APDU and returning a result of the signature operation; returning the result of the signature operation containing a signature value in a case that the signature operation is successful. 
         [0011]    The method further includes: 
         [0012]    invoking a card operating function corresponding to a second parameter of a card operating interface function to perform an operation on the card in a case that the card operating interface function is invoked includes: 
         [0013]    invoking a clearing a card interface function to clear data and a file structure in the card in a case that a value of a second parameter of the card operating interface function is a first value; 
         [0014]    invoking a writing a key interface function to write a key in the card in a case that the value of the second parameter of the card operating interface function is a second value; and 
         [0015]    invoking a generating a key pair interface function to generate a key pair in the card in a case that the value of the second parameter of the card operating interface function is a third value. 
         [0016]    Further, in a case that the clearing a card interface function is invoked, a master file (MF) in the card is selected, a deleting an in-card file interface function is invoked to delete the master file. 
         [0017]    The method further comprises: 
         [0018]    in a case that the deleting an in-card file interface function is invoked, the following steps are performed: 
         [0019]    step 1 of selecting a file by invoking the selecting a file interface function according to a second parameter of the deleting an in-card file interface function and obtaining controlling information of a file; and 
         [0020]    step 2 of building APDU for deleting a file according to the obtained controlling information of the file and deleting the file by transmitting the APDU for deleting a file. 
         [0021]    Further, in a case that the writing a key interface function is invoked, the following steps are performed: 
         [0022]    step 1 of initializing information related to the key and a key modular length of the writing a key interface function according to a third parameter of the writing a key interface function; 
         [0023]    step 2 of creating a private key file object in a memory of a computer, obtaining information related to the private key file object and creating a private key file in the card; 
         [0024]    step 3 of setting a private key ID and the key modular length; and 
         [0025]    step 4 of writing a private key in the card and releasing the private key file object created in the memory. 
         [0026]    In a case that the generating a key pair interface function is invoked, the following steps are performed: 
         [0027]    step 1 of initializing related information and a key modular length of a key of the generating a key pair interface function according to a third parameter of the generating a key pair interface function; 
         [0028]    step 2 of creating a private key file object in the memory of the computer, obtaining related information of the private key file object and creating a private key file in the card; 
         [0029]    step 3 of creating a public key file object in the memory of the computer, obtaining related information of the public key file object and creating a public key file in the card; 
         [0030]    step 4 of setting a public key ID and a private key ID and the key modular length; and 
         [0031]    step 5 of generating a key pair and releasing the public key file object and the private key file object created in the memory. 
         [0032]    Further, the private key file object is created by invoking a newly creating a file interface function; the related information of the private key file object is obtained according to a fifth parameter of the newly creating a file interface function. 
         [0033]    The operation of performing selecting the file according to attribution of the first structure in the selecting a file interface function includes: in a case that type attribution of the first structure is a second preset value, length attribution is 2 and a first byte of file ID attribution is a fourth preset value, pseudo file controlling information is built as the result of the operation of selecting the file. The second preset value is SC_PATH_TYPE_DF_NAME and the fourth preset value is 0x29. 
         [0034]    The method further includes: 
         [0035]    in a case that the newly creating a file interface function is invoked, the following steps are performed: 
         [0036]    step 1 of obtaining related information of a file from a configuration file according to a second parameter of the newly creating a file interface function; and 
         [0037]    step 2 of creating the file in the card by invoking the creating a file interface function according to the obtained related information of the file; 
         [0038]    in a case that a newly creating a standard file interface function is invoked, the following steps are performed: 
         [0039]    step 1 of obtaining information related to a standard file from a configuration file according to a second parameter of the newly creating a standard file interface function; and 
         [0040]    step 2 of creating the standard file in the card by invoking the creating a file interface function according to the information related to the standard file. 
         [0041]    The method further includes: 
         [0042]    in a case that the creating a file interface function is invoked, the following steps are performed: 
         [0043]    step 1 of building file controlling information; and 
         [0044]    step 2 of building APDU for creating a file according to the file controlling information and creating the file by transmitting the APDU for creating a file. 
         [0045]    The method further includes: 
         [0046]    in a case that a creating a PIN code interface function is invoked, the following steps are performed: 
         [0047]    step 1 of defining and initializing a PIN code object; 
         [0048]    step 2 of obtaining the PIN code object according to a first parameter of the writing a key interface function and invoking the writing a key interface function to write a secret file in the card; and 
         [0049]    step 3 of buffering the PIN code object in the memory. 
         [0050]    In a case that the interface function is invoked, the method further includes locating a card to performs a specific operation according to a parameter transferred in from outside by the interface function and checking context environment attribution of the card. 
         [0051]    By implementing the present application, the middleware and the smart card device are better combined and used under the OpenSC, which helps pushing the smart card device manufacturers to develop and apply multiple functions of the smart card device under OpenSC. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0052]      FIG. 1  is a flow chart in a case that a clearing a card interface function is invoked in the present embodiment of the present application; 
           [0053]      FIG. 2  is a flow chart in a case that a generating a key pair interface function is invoked in the present embodiment of the present application; 
           [0054]      FIG. 3  is a flow chart in a case that a newly creating a file interface function is invoked in the present embodiment of the present application; 
           [0055]      FIG. 4  is a flow chart in a case that a newly creating a standard file interface function is invoked in the present embodiment of the present application; 
           [0056]      FIG. 5  is a flow chart in a case that a writing a key interface function is invoked in the present embodiment of the present application; 
           [0057]      FIG. 6  is a flow chart in a case that a creating a PIN code interface function is invoked in the present embodiment of the present application; 
           [0058]      FIG. 7  is a flow chart in a case that a creating a file interface function is invoked in the present embodiment of the present application; 
           [0059]      FIG. 8  is a flow chart in a case that a deleting an in-card file interface function is invoked in the present embodiment of the present application; 
           [0060]      FIG. 9  is a flow chart in a case that a signature interface function is invoked in the present embodiment of the present application; 
           [0061]      FIG. 10  is a flow chart in a case that a setting a security environment interface function is invoked in the present embodiment of the present application; and 
           [0062]      FIG. 11  is a flow chart in a case that an initializing interface function is invoked in the present embodiment of the present application. 
       
    
    
     DETAILED DESCRIPTION 
       [0063]    The technical solutions of the embodiments of the disclosure are described clearly and completely in conjunction with the accompanying drawings as follows. Apparently, the described embodiments are merely a part of but not all of the embodiments according to the disclosure. Based on the described embodiments of the disclosure, other embodiments obtained by those of ordinary skill in the art without any creative work belong to the scope of the disclosure. 
         [0064]    The present embodiment provides a method for implementing software and hardware drive supporting OpenSC. For example, when a middleware accesses a smart card device, the method is implemented by invoking an interface function by the middleware. The interface function may include part or all of the following interface functions: clearing a card interface function, generating a key pair interface function, selecting a file interface function, newly creating a file interface function, newly creating a standard file interface function, writing a key interface function, creating a PIN code interface function, creating a file interface function, a card operating interface function, deleting an in-card file interface function, signature interface function and setting a security environment interface function. The method includes: 
         [0065]    The interface functions referred in the present application have an external incoming parameter card. When interface functions are invoked, a card which performs a specific operation is determined firstly according to the parameter card and context environment attribution of the card is checked and operation is performed on the determined card. In the following parts of the present embodiment, the parameter card is mentioned in part of the interface functions, other parts of the interface functions in which the parameter card has not been mentioned are all contain the parameter card and the functions of the parameter card are the same and not be repeated. 
         [0066]    In a case that the clearing a card interface function is invoked, as shown by  FIG. 1 , following operation is performed. 
         [0067]    The clearing a card interface function is a erase_card, which includes a first parameter card; a card is determined according to the parameter card and the context environment attribution of the card is checked; whether the selecting a file interface and the deleting a file interface are supported is determined, in a case that the selecting a file interface and the deleting a file interface are supported, step 1-1 and step 1-2 is executed; otherwise, it is returned that the selecting a file interface and the deleting a file interface are not supported. The first parameter card is obtained from external, which is not limited by the present embodiment. 
         [0068]    In step 1-1, a master file (MF file) inside the card is selected. 
         [0069]    The master file inside the card is selected by invoking the selecting a file interface function select file. 
         [0070]    In step 1-2, the MF file is deleted. 
         [0071]    An operation of clearing card inbuilt data is performed by invoking a card operation interface function card_ctl; a value of a second parameter of the card operation interface function card_ctl, i.e. cmd, is SC_CARDCTL_ERASE_CARD. In the present embodiment, MF file is deleted by invoking the card operation interface function card_ctl. 
         [0072]    In a case that the generating a key pair interface function is invoked, as shown by  FIG. 2 , following operation is performed. 
         [0073]    The generating a key pair interface function is generate_key, a first parameter profile and a third parameter obj in the function is obtained from external. 
         [0074]    In step 2-1, a local variable of the generating a key pair interface function is initialized. 
         [0075]    Information related to a key and a module length of the key is initialized according to a third parameter obj in the function generate_key. In addition, a key reference value is initialized. 
         [0076]    In step 2-2, a private key file object is created in a memory of a computer, information related to the private key file object is obtained and a private key file is created in the card. 
         [0077]    The newly creating a file interface function cosm_new_file is invoked to create the private key file object in the memory of the computer according to a first parameter profile in the function generate_key. In this case, a third parameter in the function cosm_new_file is SC_PKCS15_TYPE_PRKEY_RSA which indicates that a file object type is a private key file; a fifth parameter in the function cosm_new_file is file which is a structure pointer of a file memory object; information related to the private key file object is obtained by parameter file. 
         [0078]    In step 2-3, a public key file object is created in the memory of the computer, information related to public key file object is obtained; a public key file is created in the card. 
         [0079]    The newly creating a file interface function cosm_new_file is invoked according to a second parameter profile in the function generate_key to create the public key file object in the memory; in this case, a third parameter of the function cosm_new_file is SC_PKCS15_TYPE_PUBKEY_RSA which indicates that the file object type is a public key file object; a fifth parameter in the function cosm_new_file is pukf which is a structure pointer of a file memory object; information related to the public key file object is obtained by the parameter pukf. 
         [0080]    In step 2-4, public key structure attribution and private key structure attribution are set. 
         [0081]    Step 2-4 includes:
       gendat.prkey_id=file-&gt;id; // set a private key ID   gendat.pukey_id=pukf-&gt;id; // set a public key ID   gendat.key_length=keybits, gendat.modulus=NULL; // set a key modular length, set a gendat.modulus as NULL.       
 
         [0085]    The above private key ID and the public key ID is a part content of the information related to a key. 
         [0086]    In step 2-5, a key pair is generated and the public key file object and the private key file object created in the memory are released. 
         [0087]    Step 2-5 may include generating the key pair by invoking a card operating interface function card_ctl, where a value of a command filed cmd of the card operating interface function is SC_CARDCTL_ENTERSAFE_GENERATE_KEY. 
         [0088]    In a case that the selecting a file interface function select_file is invoked, following operation is performed: an operation of selecting a file is performed according to attribution of a first structure in the function select_file, a result of the operation of the selecting the file is returned; when the operation of the selecting the file is performed successfully, the result of the operation of the selecting the file includes file controlling information, which is specifically includes: 
         [0089]    an peration function is selected according to type attribution of a first structure in function select_file; the type attribution of the first structure in the function select_file is n_path-&gt;type in the present embodiment. 
         [0090]    In a case that a value of the in_path-&gt;type is a first preset value, a first preset function is executed and an executed result is returned. 
         [0091]    The first preset value is SC_PATH_TYPE_DF_NAME; the first preset function is select_aid in the present embodiment. 
         [0092]    In a case that the value of the in_path-&gt;type is a second preset value, whether length attribution of the first structure in the function select_file is equal to 2 is determined, the function select_file returns an error code if the length attribution is not equal to 2; step 1 and step 2 are executed if the length attribution is equal to 2. 
         [0093]    In the present embodiment, in a case that the second preset value is SC_PATH_TYPE_FILE_ID, the length attribution of the first structure is in_path-&gt;len, the error code returned by the function select_file is SC_ERROR_INVALID_ARGUMENTS. 
         [0094]    In step 1, a structure pointer is defined and an initial value of the structure pointer is set as null. 
         [0095]    In the present embodiment, the defined structure pointer may be sc_file_t*file. 
         [0096]    In step 2, whether a first byte of file ID attribution of a first structure in function select_file is a fourth preset value is determined, pseudo file controlling information is built and a result of the operation is returned if the first byte of file ID attribution of the first structure in function select_file is the fourth preset value; otherwise, APDU of a selected file is built and a file is selected by sending the built APDU, the result of the operation is returned. 
         [0097]    The fourth preset value is 0x29, the first byte of the file ID attribution of the first structure is in_path-&gt;value[0] and the value of 0x29 indicates that the file to be selected is a private key file; the APDU is sent by invoking a function sc_transmit_apdu, data returned by function sc_transmit_apdu is checked so as to determine whether the operation of selecting a file is successful, file controlling information is obtained by invoking a function construct_process_fci if the operation of selecting a file is successful, the function select_file returns a success result; otherwise, the function select_file returns an error code. 
         [0098]    Further, when the operation of selecting a file is successful and a selected file type is DF, step 2 further includes updating related parameters in cache attribution card-&gt;cache of a second structure in the function select_file and assigning a parameter file to *file_out. 
         [0099]    In a case that the value of in_path-&gt;type is a third preset value, a third preset function is executed and an execution result is returned. 
         [0100]    In the present embodiment, the third preset value is SC_PATH_TYPE_PATH and the third preset function is select_path. 
         [0101]    In a case that the value of in_path-&gt;type is another value, an error code is returned. 
         [0102]    The error code is SC_ERROR_INVALID_ARGUMENTS. 
         [0103]    In a case that the newly creating a file interface function is invoked, as shown by  FIG. 3 , following operation is executed. 
         [0104]    In this case, the newly creating a file interface function is cosm_new_file, the function includes a first parameter profile and a second parameter card which are obtained from external; a card is determined according to the second parameter card and the context environment attribution of the card is checked; whether creating a file interface is supported is determined, step 3-1 and step 3-2 are executed if the creating a file interface is supported; otherwise, it is returned that the creating a file interface is not supported. 
         [0105]    In step 3-1, information related to a file is obtained from a configuration file. 
         [0106]    Information related to the file is obtained from the configuration file by invoking obtaining file information function sc_profile_get_file according to a first parameter profile of the function cosm_new_file. 
         [0107]    In step 3-2, the file is created inside the card according to the obtained information related to the file. 
         [0108]    In the present embodiment, based on the difference of obtained information related to the file, the file, which may be MF, SKey-MF or DIR, is created inside the card by invoking the creating a file interface function create_file. 
         [0109]    In a case that the newly creating a standard file interface function is invoked, as shown by  FIG. 4 , following operations are performed. 
         [0110]    In this case, the newly creating a standard file interface function is cosm_new_PKCS#15_file, the function includes a first parameter profile and a second parameter card which are obtained from external; the card is determined according to the second parameter card and the context environment attribution of the card is checked; whether the creating a file interface is supported is determined, step 4-1 and step 4-2 are executed if the creating a file interface is supported; otherwise, it is returned that the creating a file interface is not supported. 
         [0111]    In step 4-1, information related to a standard file is obtained from a configuration file. 
         [0112]    The information related to the standard file is obtained from the configuration file by invoking an obtaining file information function sc_profile_get_file according to a first parameter profile of the function cosm_new_PKCS#15_file. 
         [0113]    In step 4-2, a standard file is created inside the card according to obtained information related to the standard file. 
         [0114]    In the present embodiment, based on difference of the obtained information related to the standard file, the standard file is created inside the card by invoking a creating a file interface function create_file. 
         [0115]    In the present embodiment, the creating a standard file interface function is configured to create a file defined by PKCS#15 standard inside the card; the file includes PKCS15-AppDF, SKey-AppDF, MAXPIN, PKCS15-ODF, PKCS15-TokenInfo, PKCS15-UnusedSpace, PKCS15-AODF, PKCS15-PrKDF, PKCS15-PuKDF, PKCS15-CDF, PKCS 15-DODF. 
         [0116]    In a case that the writing a key interface function is invoked, as shown by  FIG. 5 , following operations are performed. 
         [0117]    In this case, the writing a key interface function is write_key; the function is configured to write a key file into the card. A second parameter profile and a third parameter obj in the function write_key are obtained from external. 
         [0118]    In step 5-1, a local variable of the writing a key interface function is initialized. 
         [0119]    Information related to a key and a key modular length is initialized according to a third parameter obj of the function write_key. Further, a key reference value is initialized as well. 
         [0120]    In step 5-2, a private key file object is created in the memory of the computer, information related to the private key file object is obtained; a private key file is created inside the card. 
         [0121]    The private key file object is created in the memory by invoking a newly creating a file interface function cosm_new_file according to the second parameter profile of the function write_key; in this case, a third parameter of the function cosm_new_file is SC_PKCS15_TYPE_PRKEY_RSA which indicates that a file object type is the private key file object; a fifth parameter of function cosm_new_file is file which is a structure pointer of a file memory object; information related to the private key file object is obtained by parameter file. 
         [0122]    In step 5-3, private key structure attribution is set. 
         [0123]    Step 5-3 includes:
       gendat.prkey_id=file-&gt;id; // set a private key ID   gendat.key_length=keybits, gendat.modulus=NULL; // set a key modular length, set gendat.modulus as NULL.       
 
         [0126]    In step 5-4, a private key is written in the card and the private key file object created in the memory is released. 
         [0127]    Step 5-4 specifically includes: writing the private key in the card by invoking card operating interface function card_ctl; in this case, command field cmd of the function card_ctl is SC_CARDCTL_ENTERSAFE_WRITE_KEY. 
         [0128]    In a case that the creating a PIN code interface function is invoked, as shown by  FIG. 6 , following operations are performed. 
         [0129]    In this case, the creating a PIN code interface function is create_pin, in which a first parameter profile, a second parameter pin_obj, a third parameter pin, a fourth parameter pin_len, a fifth parameter puk and a sixth parameter puk_len are obtained from external. 
         [0130]    In step 6-1, a PIN code object is defined and initialized. 
         [0131]    Step 6-1 may include setting a PIN type, an access control right, a Key ID and maximum retry times according to the second parameter pin_obj of the function create_pin. 
         [0132]    According to the first parameter profile of the function create_pin, a function sc_profile_get_pin_id is invoked to obtain the key ID and a maximum retry times is obtained by invoking a function sc_profile_get_pin_retries. 
         [0133]    In step 6-2, a secret file is written into the card. 
         [0134]    The writing a key interface function is invoked by invoking a card operating function card_ctl; the secret file is written into the card; the secret file is written into the card by invoking the writing a key interface function in the case that a value of command field cmd of function card_ctl is SC_CARDCTL_ENTERSAFE_WRITE_KEY. In this case, a PIN code object can be obtained according to a first parameter of the writing a key interface function. 
         [0135]    In step 6-3, the PIN code object is buffered. 
         [0136]    The PIN code object is buffered in the memory by invoking a function sc_pkcs15_pincache_add. 
         [0137]    Further, a PUK code may be generated by performing step 6-1 and step 6-2 via invoking the creating a PIN code interface function create_pin. 
         [0138]    In a case that the creating a file interface function is invoked, as shown by  FIG. 7 , following operations are performed. 
         [0139]    In this case, the creating a file interface function is create_file. 
         [0140]    In step 7-1, file controlling information is created. 
         [0141]    The file controlling information may be created by invoking a function construct_fci; further, if the card does not support function construct_fci, SC_ERROR_NOT_SUPPORTED is returned. 
         [0142]    Further, before step 7-1, the method may include defining and initializing a local variable of the creating a file interface function. 
         [0143]    In step 7-2, an APDU for creating a file is built and a file is created by sending the APDU. 
         [0144]    A built APDU is transmitted by invoking a function sc_transmit_apdu and a return value and a state code of the function sc_transmit_apdu is received. Whether creating a file is successful is determined according to the return value and the state code. 
         [0145]    In a case that the card operating interface function is invoked, following operations are performed. 
         [0146]    In this case, the card operating interface function is card_ctl; a type of an operation to be executed is determined according to a value of a second parameter of the function, i.e. a command field cmd, which is obtained from external. 
         [0147]    In a case that the value of cmd is a first value, the clearing a card interface function is invoked to clear the data and the file structure inside the card. 
         [0148]    The first value may be SC_CARDCTL_ERASE_CARD. 
         [0149]    In a case that the value of cmd is a second value, the writing a key interface function is invoked so as to write a key in the card. 
         [0150]    The second value may be SC_CARDCTL_ENTERSAFE_WRITE_KEY. 
         [0151]    In a case that the value of cmd is a third value, a key pair is generated in the card by invoking the generating a key pair interface function. 
         [0152]    The third value may be SC_CARDCTL_ENTERSAFE_GENERATE_KEY. 
         [0153]    In a case that the value of cmd is a fourth value, a sequence value of the card is obtained by invoking an obtaining card sequence number interface function. 
         [0154]    The fourth value may be SC_CARDCTL_GET_SERIALNR. 
         [0155]    In a case that the value of cmd is another value, SC_ERROR_NOT_SUPPORTED is returned which indicates that it&#39;s not supported by the card. 
         [0156]    In a case that the deleting an in-card file interface function is invoked, as shown by  FIG. 8 , following operations are performed. 
         [0157]    In this case, the deleting an in-card file interface function is delete_file. A first parameter card and a second parameter file of the function delete_file are obtained from external. The card is determined according to the first parameter card and context environment attribution of the card is checked; whether a deleting a file interface and a selecting a file interface are supported is determined, step 8-1 to step 8-3 are executed if the deleting a file interface and the selecting a file interface are supported; otherwise, it is returned that the deleting a file interface and the selecting a file interface are not supported. 
         [0158]    In step 8-1,a local variable of the deleting an in-card file interface function is defined. 
         [0159]    In step 8-2, a file is selected by invoking the selecting a file interface function and file controlling information is obtained. 
         [0160]    The file interface function is invoked according to the second parameter file of the function delete_file. Further, if selecting a file is failed, the selecting a file interface returns an invalid parameter. For example, SC_ERROR_INVALID_ARGUMENTS is returned. 
         [0161]    In step 8-3, an APDU for deleting a file is built according to the obtained file controlling information and the file is deleted by transmitting the APDU. 
         [0162]    The APDU is transmitted by invoking function sc_transmit_apdu and whether deleting a file is successful is determined according to a return value and a state code of the function sc_transmit_apdu. 
         [0163]    In a case that the signature interface function is invoked, as shown by  FIG. 9 , following operations are performed. 
         [0164]    In this case, the signature interface function is decipher. A first parameter card, a second parameter plain, a third parameter plain_length, a fourth parameter signature, a fifth parameter signature_length are obtained from external. Context environment attribution of the card is checked according to the first parameter card and whether a signature interface is supported is determined; step 9-1 and step 9-2 are executed if the signature interface is supported; otherwise, it is returned that the signature interface is not supported. 
         [0165]    In step 9-1, a local variable of the signature interface function is defined. 
         [0166]    In step 9-2, an APDU for signature is built; a signature operation is performed on an original text to be signed in a set security environment by sending the APDU. 
         [0167]    Signed APDU is built according to the second parameter plain and the third parameter plain_length, in which the second parameter plain indicates the original text and the third parameter plain_length indicates the length of the original text. 
         [0168]    The APDU is transmitted by invoking a function sc_transmit_apdu and whether the signature is successful is determined according to a return value and a state code of the function sc_transmit_apdu; the signature interface function returns a signature operation result by the fourth parameter signature and a fifth parameter signature_length. When the signature is successful, the signature operation result returned by the signature interface includes a signature value. In this case, the fourth parameter signature indicates a value of a signature and the fifth parameter signature_length indicates a length of the signature. 
         [0169]    In a case that the setting a security environment interface function is invoked, as shown by  FIG. 10 , following operations are performed. 
         [0170]    In this case, the setting a security environment interface function is set_security_env, a first parameter card and a second parameter env of the function set_security_env are obtained from external. The card is determined according to the first parameter card and context environment attribution of the card is checked. Whether a setting a security environment interface is supported is determined, step 10-1 and step 10-2 are executed if the set security environment interface is supported; otherwise, it is returned that the setting a security environment interface is not supported. 
         [0171]    In step 10-1, an APDU for setting a security environment is built. 
         [0172]    The APDU for setting a security environment is built according to the second parameter env of the function set_security_env; the key file attribution of the file controlling information can be obtained according to the second parameter evn. Further, to build the APDU for setting a security environment, besides the obtained key file attribution of the file controlling information, other attribution which reads from a preset cos manual is needed. 
         [0173]    In step 10-2, a security environment is set by transmitting the APDU. 
         [0174]    The APDU is transmitted by invoking a function sc_transmit_apdu and whether an operation of setting a security environment is successful is determined according to a return value and a state code of the function sc_transmit_apdu; the setting a security environment interface returns a return value which indicates the setting is successful or not. 
         [0175]    In a case that an initializing interface function is invoked, as shown by  FIG. 11 , following operations are performed. 
         [0176]    In this case, the initializing interface function is init. 
         [0177]    In step 11-1, a ciphertext communication environment is built according to a communication key type of the card. 
         [0178]    The communication key type may be DES or AES. The communication key type is determined by return data which is obtained by invoking a function get_data. 
         [0179]    In step 11-2, a key digit number supported by the card is set. 
         [0180]    For example, the key digit number supported by the card may be 512 or 2048. 
         [0181]    In addition, the initializing interface returns an initializing result which indicates that the initializing is successful or not. 
         [0182]    The described embodiments are only preferred embodiments of the application and the embodiments are not intended to limit the application. Any alteration or change easily obtained by those skilled in the art based on the application should fall in the scope of protection of the application.