当前位置: 首页>>代码示例>>Java>>正文


Java CardChannel.transmit方法代码示例

本文整理汇总了Java中javax.smartcardio.CardChannel.transmit方法的典型用法代码示例。如果您正苦于以下问题:Java CardChannel.transmit方法的具体用法?Java CardChannel.transmit怎么用?Java CardChannel.transmit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.smartcardio.CardChannel的用法示例。


在下文中一共展示了CardChannel.transmit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReadPhoto

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
@Test
public void testReadPhoto() throws Exception {
	TerminalFactory terminalFactory = TerminalFactory.getDefault();
	CardTerminals cardTerminals = terminalFactory.terminals();
	CardTerminal cardTerminal = cardTerminals.list().get(0);
	Card card = cardTerminal.connect("T=0");
	CardChannel cardChannel = card.getBasicChannel();
	// select file
	cardChannel.transmit(
			new CommandAPDU(0x00, 0xA4, 0x08, 0x0C, new byte[] { 0x3F, 0x00, (byte) 0xDF, 0x01, 0x40, 0x35 }));
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	int offset = 0;
	ResponseAPDU responseApdu;
	do {
		// read binary
		responseApdu = cardChannel.transmit(new CommandAPDU(0x00, 0xB0, offset >> 8, offset & 0xFF, 0xff));
		baos.write(responseApdu.getData());
		offset += responseApdu.getData().length;
	} while (responseApdu.getData().length == 0xff);
	BufferedImage photo = ImageIO.read(new ByteArrayInputStream(baos.toByteArray()));
	JOptionPane.showMessageDialog(null, new ImageIcon(photo));
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:23,代码来源:PcscTest.java

示例2: transmit

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
private ResponseAPDU transmit(CardChannel channel, CommandAPDU cmd)
        throws CardException {
    log(cmd);

    long elapsed = -System.currentTimeMillis();
    ResponseAPDU response = channel.transmit(cmd);
    elapsed += System.currentTimeMillis();
    lastTransmitTime = elapsed;
    log(response, elapsed);

    return response;
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:13,代码来源:CardMPCPlayer.java

示例3: testCardDataFile

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
@Test
public void testCardDataFile() throws Exception {
	PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
	if (false == pcscEid.isEidPresent()) {
		LOG.debug("insert eID card");
		pcscEid.waitForEidPresent();
	}

	try {
		CardChannel cardChannel = pcscEid.getCardChannel();

		while (true) {
			CommandAPDU getCardApdu = new CommandAPDU(0x80, 0xe4, 0x00, 0x00, 0x1c); // Le
																						// =
																						// 0x1c
			ResponseAPDU responseApdu = cardChannel.transmit(getCardApdu);
			if (0x9000 != responseApdu.getSW()) {
				fail("SW error: " + Integer.toHexString(responseApdu.getSW()));
			}
			LOG.debug(Hex.encodeHexString(responseApdu.getData()));
		}
	} finally {
		pcscEid.close();
	}
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:26,代码来源:PcscTest.java

示例4: testGetChallenge

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
@Test
public void testGetChallenge() throws Exception {
	PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
	if (false == pcscEid.isEidPresent()) {
		LOG.debug("insert eID card");
		pcscEid.waitForEidPresent();
	}

	CardChannel cardChannel = pcscEid.getCardChannel();

	int size = 256;
	CommandAPDU getChallengeApdu = new CommandAPDU(0x00, 0x84, 0x00, 0x00, new byte[] {}, 0, 0, size);
	ResponseAPDU responseApdu;
	responseApdu = cardChannel.transmit(getChallengeApdu);
	if (0x9000 != responseApdu.getSW()) {
		fail("get challenge failure: " + Integer.toHexString(responseApdu.getSW()));
	}
	LOG.debug("challenge: " + Hex.encodeHexString(responseApdu.getData()));
	assertEquals(size, responseApdu.getData().length);

	pcscEid.close();
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:23,代码来源:PcscTest.java

示例5: transmitTestCommand

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
static void transmitTestCommand(CardChannel channel) throws Exception {
    ResponseAPDU r = channel.transmit(new CommandAPDU(C1));
    byte[] rb = r.getBytes();
    if ((Arrays.equals(rb, R1a) == false) && (Arrays.equals(rb, R1b) == false)) {
        System.out.println("expected: " + toString(R1a));
        System.out.println("received: " + toString(rb));
        throw new Exception("Response does not match");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:Utils.java

示例6: transmit

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
public static ResponseAPDU transmit(CardChannel channel, CommandAPDU cmd)
        throws CardException {
    log(cmd);

    long elapsed = -System.currentTimeMillis();
    ResponseAPDU response = channel.transmit(cmd);
    elapsed += System.currentTimeMillis();
    m_lastTransmitTime = elapsed;
    log(response, elapsed);

    return response;
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:13,代码来源:CardManagement.java

示例7: transmit

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
public ResponseAPDU transmit(byte[] command, Card card, CardChannel cardChannel) throws CardException {
	if (this.ioctl == null) {
		// PPDU
		return cardChannel.transmit(new CommandAPDU(0xff, 0xc2, 0x01, this.feature, command));
	} else {
		byte[] result = card.transmitControlCommand(this.ioctl, command);
		ResponseAPDU responseApdu = new ResponseAPDU(result);
		return responseApdu;
	}
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:11,代码来源:PcscEid.java

示例8: logoff

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
public void logoff(String readerName) throws Exception {
	this.view.addDetailMessage("logoff from reader: \"" + readerName + "\"");
	TerminalFactory factory = TerminalFactory.getDefault();
	CardTerminals cardTerminals = factory.terminals();
	CardTerminal cardTerminal = cardTerminals.getTerminal(readerName);
	if (null == cardTerminal) {
		this.view.addDetailMessage("logoff: card reader not found: " + readerName);
		List<String> readerList = getReaderList();
		this.view.addDetailMessage("reader list: " + readerList);
		// throw new RuntimeException("card reader not found: " +
		// readerName);
		// we won't fail in this case...
		return;
	}
	Card card = cardTerminal.connect("T=0");
	try {
		CardChannel cardChannel = card.getBasicChannel();
		CommandAPDU logoffApdu = new CommandAPDU(0x80, 0xE6, 0x00, 0x00);
		ResponseAPDU responseApdu = cardChannel.transmit(logoffApdu);
		this.view.addDetailMessage("logoff... " + readerName);
		if (0x9000 != responseApdu.getSW()) {
			this.view.addDetailMessage("logoff status word: " + Integer.toHexString(responseApdu.getSW()));
			if (0x6e00 == responseApdu.getSW()) {
				// BUD001 smart card reader work-around
				return;
			}
			throw new RuntimeException("logoff failed");
		}
	} finally {
		card.disconnect(true);
	}
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:33,代码来源:PcscEid.java

示例9: testNonRepSignPlainText

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
/**
 * Creates a non-repudiation signature with plain text.
 * <p/>
 * Remark: "Enter NonRep PIN" should maybe be replaced with "Enter Sign PIN"
 * . Fixed in V010Z.
 * 
 * @throws Exception
 */
@Test
@QualityAssurance(firmware = Firmware.V015Z, approved = true)
public void testNonRepSignPlainText() throws Exception {
	CardChannel cardChannel = this.pcscEid.getCardChannel();

	List<X509Certificate> signCertChain = this.pcscEid.getSignCertificateChain();

	CommandAPDU setApdu = new CommandAPDU(0x00, 0x22, 0x41, 0xB6,
			new byte[] { 0x04, // length of following data
					(byte) 0x80, // algo ref
					0x01, // rsa pkcs#1
					(byte) 0x84, // tag for private key ref
					(byte) 0x83 }); // non-rep key
	ResponseAPDU responseApdu = cardChannel.transmit(setApdu);
	assertEquals(0x9000, responseApdu.getSW());

	this.pcscEid.verifyPin();

	String textMessage = "My Testcase";
	AlgorithmIdentifier algoId = new AlgorithmIdentifier("2.16.56.1.2.1.3.1");
	DigestInfo digestInfo = new DigestInfo(algoId, textMessage.getBytes());
	CommandAPDU computeDigitalSignatureApdu = new CommandAPDU(0x00, 0x2A, 0x9E, 0x9A, digestInfo.getDEREncoded());

	responseApdu = cardChannel.transmit(computeDigitalSignatureApdu);
	assertEquals(0x9000, responseApdu.getSW());
	byte[] signatureValue = responseApdu.getData();
	LOG.debug("signature value size: " + signatureValue.length);

	Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
	cipher.init(Cipher.DECRYPT_MODE, signCertChain.get(0));
	byte[] signatureDigestInfoValue = cipher.doFinal(signatureValue);
	ASN1InputStream aIn = new ASN1InputStream(signatureDigestInfoValue);
	DigestInfo signatureDigestInfo = new DigestInfo((ASN1Sequence) aIn.readObject());
	LOG.debug("result algo Id: " + signatureDigestInfo.getAlgorithmId().getObjectId().getId());
	assertEquals("2.16.56.1.2.1.3.1", signatureDigestInfo.getAlgorithmId().getObjectId().getId());
	assertArrayEquals(textMessage.getBytes(), signatureDigestInfo.getDigest());
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:46,代码来源:SecurePinPadReaderTest.java

示例10: testNonRepSignPKCS1_SHA1

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
/**
 * When creating a non-repudiation signature using PKCS#1-SHA1 (non-naked)
 * the digest value should also be confirmed via the secure pinpad reader.
 * 
 * @throws Exception
 */
@Test
@QualityAssurance(firmware = Firmware.V015Z, approved = true)
public void testNonRepSignPKCS1_SHA1() throws Exception {
	CardChannel cardChannel = this.pcscEid.getCardChannel();

	List<X509Certificate> signCertChain = this.pcscEid.getSignCertificateChain();

	CommandAPDU setApdu = new CommandAPDU(0x00, 0x22, 0x41, 0xB6,
			new byte[] { 0x04, // length of following data
					(byte) 0x80, // algo ref
					0x02, // RSA PKCS#1 SHA1
					(byte) 0x84, // tag for private key ref
					(byte) 0x83 }); // non-rep key
	ResponseAPDU responseApdu = cardChannel.transmit(setApdu);
	assertEquals(0x9000, responseApdu.getSW());

	this.pcscEid.verifyPin();

	byte[] data = "My Testcase".getBytes();
	MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
	byte[] digestValue = messageDigest.digest(data);

	CommandAPDU computeDigitalSignatureApdu = new CommandAPDU(0x00, 0x2A, 0x9E, 0x9A, digestValue);

	responseApdu = cardChannel.transmit(computeDigitalSignatureApdu);
	assertEquals(0x9000, responseApdu.getSW());
	byte[] signatureValue = responseApdu.getData();
	LOG.debug("signature value size: " + signatureValue.length);

	Signature signature = Signature.getInstance("SHA1withRSA");
	signature.initVerify(signCertChain.get(0).getPublicKey());
	signature.update(data);
	boolean result = signature.verify(signatureValue);
	assertTrue(result);
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:42,代码来源:SecurePinPadReaderTest.java

示例11: pcscMSE_SET

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
@Test
public void pcscMSE_SET() throws Exception {
	this.messages = new Messages(Locale.GERMAN);
	PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
	if (false == pcscEid.isEidPresent()) {
		LOG.debug("insert eID card");
		pcscEid.waitForEidPresent();
	}
	CardChannel cardChannel = pcscEid.getCardChannel();
	try {
		CommandAPDU setApdu = new CommandAPDU(0x00, 0x22, 0x41, 0xB6,
				new byte[] { 0x04, // length of following data
						(byte) 0x80, // algo ref
						// 0x01, // rsa pkcs#1
						// 0x02, // PKCS1-SHA1
						// 0x04, // PKCS1-MD5
						// 0x08, // PKCS1-SHA256
						// 0x10, // PKCS1-PSS-SHA1
						0x20, // PKCS1-PSS-SHA256
						// (byte) 0xfb, // foobar
						(byte) 0x84, // tag for private key ref
						PcscEid.AUTHN_KEY_ID });
		ResponseAPDU responseAPDU = cardChannel.transmit(setApdu);
		assertEquals(0x9000, responseAPDU.getSW());
	} finally {
		pcscEid.close();
	}
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:29,代码来源:PcscTest.java

示例12: unblockPin

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
private void unblockPin(byte[] puk12, CardChannel cardChannel) throws CardException {
	byte[] unblockPinData = new byte[] { 0x2C, puk12[0], puk12[1], puk12[2], puk12[3], puk12[4], puk12[5],
			(byte) 0xFF };

	CommandAPDU changePinApdu = new CommandAPDU(0x00, 0x2C, 0x00, 0x01, unblockPinData);
	ResponseAPDU responseApdu = cardChannel.transmit(changePinApdu);
	if (0x9000 != responseApdu.getSW()) {
		throw new RuntimeException("could not unblock PIN code");
	}
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:11,代码来源:PcscTest.java

示例13: verifyPin

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
private ResponseAPDU verifyPin(byte[] pin, CardChannel cardChannel) throws CardException {
	byte[] verifyData = new byte[] { 0x24, pin[0], pin[1], (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
			(byte) 0xFF };

	CommandAPDU verifyApdu = new CommandAPDU(0x00, 0x20, 0x00, 0x01, verifyData);
	ResponseAPDU responseApdu = cardChannel.transmit(verifyApdu);
	return responseApdu;
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:9,代码来源:PcscTest.java

示例14: testSelectPkcs15Application

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
@Test
public void testSelectPkcs15Application() throws Exception {
	CardChannel cardChannel = this.pcscEid.getCardChannel();
	byte[] aId = new byte[] { (byte) 0xa0, 0x00, 0x00, 0x01, 0x77, 0x50, 0x4b, 0x43, 0x53, 0x2d, 0x31, 0x35 };
	CommandAPDU selectApplicationApdu = new CommandAPDU(0x00, 0xA4, 0x04, 0x0C, aId);
	ResponseAPDU responseApdu = cardChannel.transmit(selectApplicationApdu);
	assertEquals(0x9000, responseApdu.getSW());
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:9,代码来源:Pkcs15Test.java

示例15: exchange

import javax.smartcardio.CardChannel; //导入方法依赖的package包/类
private static APDUResponse exchange(CardChannel channel, byte[] command) throws CardException {
	long start = System.currentTimeMillis();
	ResponseAPDU response = channel.transmit(new CommandAPDU(command));
	long duration = System.currentTimeMillis() - start;
	if (response.getSW() != SW_OK) {
		throw new RuntimeException("Invalid status " + Integer.toHexString(response.getSW()));
	}
	
	APDUResponse apduResponse = new APDUResponse();
	apduResponse.response = response.getData();
	apduResponse.exchangeTime = duration;
	return apduResponse;
}
 
开发者ID:LedgerHQ,项目名称:ledger-javacard-eligibility,代码行数:14,代码来源:LedgerEligibilityReport.java


注:本文中的javax.smartcardio.CardChannel.transmit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。