⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perso_example.cpp

📁 开发源代码的CPU卡的COS源程序。
💻 CPP
字号:
#include "inkit/jaya_reader/JayaReaderRegistry.h"#include "inkit/jaya_reader/JayaReader.h"#include "inkit/common/simu_launcher.h"#include "inkit/jaya_reader/jaya_utils.h"#include "common/str_hex.h"#include "common/jlog.h"#include <stdio.h>using namespace Jayacard;void report_error( char * msg, jresult err );JayaReader * rd = 0L;char * getChallenge = "00 84 00 00 08";char * extAuth 		= "00 82 00 00 08 FF FF FF FF FF FF FF FF";char * bootstrapMf  = "80 E0 3F 00 00";char * createBinary = "80 E0 %s 06 20 %02X FF FF %02X %02X";char * selectFid    = "00 A4 00 00 02 3F 00";char * getResponse  = "00 C0 00 00 00";char * readBinary   = "00 B0 %02X %02X 00";char * updateBinary = "00 D6 %02X %02X 00";char * changeKey	= "80 D8 00 00 1E FF FF FF FF FF FF FF FF"						" 44 03 1F 49 32 07"						" 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11";// format for changeKey is [ challenge, algo, version << 4 + attempt, attributes, LRC, CRC, value ]void exchange( char * msg, jbyte * command, int cmdLen, jbyte * response, int * respLen ){    jresult ret;	printf("%s\n", msg );    ret = rd->exchangeApdu( command, cmdLen, response, respLen );	report_error( msg, ret );}void use_jaya_reader(){    jresult ret;    jbyte command[1024], response[1024];	jbyte challenge[8];	jbyte crypted_challenge[8];    int cmdLen, respLen;   	// pwon	printf("PowerOn\n");	ret = rd->powerOn();	report_error( "powerOn", ret );	// Get Challenge	cmdLen = str2hex( command, getChallenge );    respLen=1024;	exchange( "Get Challenge", command, cmdLen, response, &respLen );	memcpy( challenge, response, 8 );	ret = jaya_external_authenticate_keys_in_file( DEFAULT_KEYFILE, 		"msk_keya", "msk_keyb", challenge, crypted_challenge );			report_error( "crypt keys", ret );	// Auth	cmdLen = str2hex( command, extAuth );	memcpy( command + 5, crypted_challenge, 8 );    respLen=1024;	exchange( "Ext Auth", command, cmdLen, response, &respLen );	// Bootstrap Filesystem	cmdLen = str2hex( command, bootstrapMf );    respLen=1024;	exchange( "Bootstrap MF", command, cmdLen, response, &respLen );	// Create EF	char buf[200];	char * fid = "30 01";	int sfi=01, size=300;	sprintf( buf, createBinary, fid, sfi, size>>8, size&0xFF );	cmdLen = str2hex( command, buf );    respLen=1024;	exchange( "Create EF", command, cmdLen, response, &respLen );	// Select EF	cmdLen = str2hex( command, selectFid );	str2hex( command + 5, fid );    respLen=1024;	exchange( "Select EF", command, cmdLen, response, &respLen );	// Get Response	cmdLen = str2hex( command, getResponse );	command[4] = response[1];    respLen=1024;	exchange( "Get Response", command, cmdLen, response, &respLen );	// Update Binary	char * data = "Jayacos rocks!\0";	sprintf( buf, updateBinary, 0, 0 ); // offset = 0x0000	cmdLen = str2hex( command, buf );	command[4] = strlen(data);	cmdLen += strlen( data );	memcpy( command + 5, (byte *) data, strlen( data ) );    respLen=1024;	exchange( "Update Binary", command, cmdLen, response, &respLen );	// Read Binary		sprintf( buf, readBinary, 0, 0 ); // offset = 0x0000	cmdLen = str2hex( command, buf );	command[4] = 30;    respLen=1024;	exchange( "Read Binary", command, cmdLen, response, &respLen );	printf("Data Read: '%s'\n", (char *) response );	// Change Key	cmdLen = str2hex( command, getChallenge );    respLen=1024;	exchange( "Get Challenge", command, cmdLen, response, &respLen );	memcpy( challenge, response, 8 );	ret = jaya_external_authenticate_keys_in_file( DEFAULT_KEYFILE, 		"msk_keya", "msk_keyb", challenge, crypted_challenge );			report_error( "crypt keys", ret );	cmdLen = str2hex( command, changeKey );	memcpy( command + 5, crypted_challenge, 8 );    respLen=1024;	exchange( "Change Key", command, cmdLen, response, &respLen );	// Get Challenge	cmdLen = str2hex( command, getChallenge );    respLen=1024;	exchange( "Get Challenge", command, cmdLen, response, &respLen );	memcpy( challenge, response, 8 );	byte key[8];	str2hex( key, "1111111111111111" );	jaya_external_authenticate_explicit_keys( key, key, challenge, crypted_challenge );			report_error( "crypt keys", ret );	// Auth	cmdLen = str2hex( command, extAuth );	memcpy( command + 5, crypted_challenge, 8 );    respLen=1024;	exchange( "Ext Auth", command, cmdLen, response, &respLen );	// Power off	printf("PowerOff\n");	ret = rd->powerOff();	report_error( "powerOff", ret );}void report_error( char * msg, jresult err ) {	if (err != JY_OK) {		fprintf( stderr, "%s: %s", msg, jerror_msg( err ) );		getchar();		exit( err );	}}void init(){	jresult ret;	jlog_disable_component("Rd T=CL");	launch_simulator();	printf("Connecting to reader %s\n", reader_name );    rd = JayaReaderRegistry::instance()->getReader( reader_name, &ret );	if (rd == NULL) {		fprintf(stderr, "Could not get pointer to %s\n", reader_name );		getchar();		exit( -1 );	}}int main(){	init();	use_jaya_reader();	getchar();	stop_simulator();	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -