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


Java Signature类代码示例

本文整理汇总了Java中javacard.security.Signature的典型用法代码示例。如果您正苦于以下问题:Java Signature类的具体用法?Java Signature怎么用?Java Signature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: OpenPGPSecureMessaging

import javacard.security.Signature; //导入依赖的package包/类
/**
 * Construct a new secure messaging wrapper.
 */
public OpenPGPSecureMessaging() {
    ssc = JCSystem.makeTransientByteArray(SSC_SIZE, 
            JCSystem.CLEAR_ON_DESELECT);
    tmp = JCSystem.makeTransientByteArray(TMP_SIZE, 
            JCSystem.CLEAR_ON_DESELECT);
    signer = Signature.getInstance(
            Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false);
    verifier = Signature.getInstance(
            Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false);
    cipher = Cipher.getInstance(
            Cipher.ALG_DES_CBC_ISO9797_M2, false);
    decipher = Cipher.getInstance(
            Cipher.ALG_DES_CBC_ISO9797_M2, false);
    
    keyMAC = (DESKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, 
            KeyBuilder.LENGTH_DES3_2KEY, false);
    keyENC = (DESKey) KeyBuilder.buildKey(
            KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, 
            KeyBuilder.LENGTH_DES3_2KEY, false);
    
    ssc_set = JCSystem.makeTransientBooleanArray((short)1, JCSystem.CLEAR_ON_DESELECT);
    ssc_set[0] = false;
}
 
开发者ID:jderuiter,项目名称:javacard-openpgpcard,代码行数:28,代码来源:OpenPGPSecureMessaging.java

示例2: setSessionKeys

import javacard.security.Signature; //导入依赖的package包/类
/**
 * Set the MAC and encryption (and decryption) session keys. Each key is a 
 * 16 byte 3DES EDE key. This method may be called at any time and will 
 * immediately replace the session key.
 * 
 * @param buffer byte array containing the session keys.
 * @param offset location of the session keys in the buffer.
 */
public void setSessionKeys(byte[] buffer, short offset) {
	// Check for empty keys
	if(Util.arrayCompare(buffer, (short)0, EMPTY_KEY, (short)0, KEY_SIZE) == 0 ||
			Util.arrayCompare(buffer, KEY_SIZE, EMPTY_KEY, (short)0, KEY_SIZE) == 0) {
		keyMAC.clearKey();
		keyENC.clearKey();
	}
	else {    	
		keyMAC.setKey(buffer, offset);
		keyENC.setKey(buffer, (short) (offset + KEY_SIZE));
    
		signer.init(keyMAC, Signature.MODE_SIGN);
    	verifier.init(keyMAC, Signature.MODE_VERIFY);
    
    	cipher.init(keyENC, Cipher.MODE_ENCRYPT);
    	decipher.init(keyENC, Cipher.MODE_DECRYPT);
	}
}
 
开发者ID:jderuiter,项目名称:javacard-openpgpcard,代码行数:27,代码来源:OpenPGPSecureMessaging.java

示例3: getBIP32AuthentiKey

import javacard.security.Signature; //导入依赖的package包/类
/**
 * This function returns the authentikey public key (uniquely derived from the Bip32 seed).
 * The function returns the x-coordinate of the authentikey, self-signed.
 * The authentikey full public key can be recovered from the signature.
 * 
 *  ins: 0x73
 *  p1: 0x00 
 *  p2: 0x00 
 *  data: none
 *  return: [coordx_size(2b) | coordx | sig_size(2b) | sig]
 */
private void getBIP32AuthentiKey(APDU apdu, byte[] buffer){
	
	// check whether the seed is initialized
	if (!bip32_seeded)
		ISOException.throwIt(SW_BIP32_UNINITIALIZED_SEED);
	
	// compute the partial authentikey public key...
       keyAgreement.init(bip32_authentikey);
       short coordx_size = keyAgreement.generateSecret(Secp256k1.SECP256K1, Secp256k1.OFFSET_SECP256K1_G, (short) 65, buffer, (short)2); // compute x coordinate of public key as k*G
       Util.setShort(buffer, (short)0, coordx_size);
       // self signed public key
       sigECDSA.init(bip32_authentikey, Signature.MODE_SIGN);
       short sign_size= sigECDSA.sign(buffer, (short)0, (short)(coordx_size+2), buffer, (short)(coordx_size+4));
       Util.setShort(buffer, (short)(coordx_size+2), sign_size);
       
       // return x-coordinate of public key+signature
       // the client can recover full public-key from the signature or
       // by guessing the compression value () and verifying the signature... 
       // buffer= [coordx_size(2) | coordx | sigsize(2) | sig]
       apdu.setOutgoingAndSend((short) 0, (short)(coordx_size+sign_size+4));
	
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:34,代码来源:CardEdge.java

示例4: testBip32Gen

import javacard.security.Signature; //导入依赖的package包/类
private static void testBip32Gen(byte[] apduBuffer) {
 byte lastStatus = STATUS_FAILED_GENERIC;
 byte flags = (byte)0x00;
 try {
  if ((nativeHmacSha512 != null) && (hmacKey != null)) { hmacKey.setKey(BITCOIN_SEED, (short)0, (short)BITCOIN_SEED.length); if ((proprietaryAPI != null) && (proprietaryAPI.hasHmacSHA512())) { proprietaryAPI.hmacSHA512(hmacKey, SEED, (short)0, (short)SEED.length, buffer, (short)0); } else { nativeHmacSha512.init(hmacKey, Signature.MODE_SIGN); nativeHmacSha512.sign(SEED, (short)0, (short)SEED.length, buffer, (short)0); } } else { HmacSha512.hmac(BITCOIN_SEED, (short)0, (short)BITCOIN_SEED.length, SEED, (short)0, (short)SEED.length, buffer, (short)0, apduBuffer, (short)0); };
  if ((Util.arrayCompare(PRIVATE_SEED, (short)0, buffer, (short)0, (short)32) == 0) &&
   (Util.arrayCompare(CHAIN_SEED, (short)0, buffer, (short)32, (short)32) == 0)) {
   lastStatus = STATUS_PASSED;
  }
  if ((nativeHmacSha512 != null) && (hmacKey != null)) {
   flags |= FLAG_NATIVE_HMAC_SHA512;
  }
  if (hmacAlgorithm == KeyBuilder.TYPE_HMAC_TRANSIENT_DESELECT) {
   flags |= FLAG_HMAC_TRANSIENT_DESELECT;
  }
  if (hmacAlgorithm == KeyBuilder.TYPE_HMAC_TRANSIENT_RESET) {
   flags |= FLAG_HMAC_TRANSIENT_RESET;
  }
 }
 catch(Exception e) {
  lastStatus = STATUS_FAILED_INTERNAL;
 }
 apduBuffer[0] = lastStatus;
 apduBuffer[1] = flags;
}
 
开发者ID:LedgerHQ,项目名称:ledger-javacard-eligibility,代码行数:26,代码来源:LedgerEligibility.java

示例5: ECPoint_Helper

import javacard.security.Signature; //导入依赖的package包/类
public ECPoint_Helper(ResourceManager rm) {
    super(rm);
    
    FLAG_FAST_EC_MULT_VIA_KA = false; // set true only if succesfully allocated and tested below
    try {
        //fnc_multiplication_x_keyAgreement = KeyAgreement.getInstance(KeyAgreement.ALG_EC_SVDP_DHC, false);
        //fnc_SignVerifyECDSA_signEngine = Signature.getInstance(Signature.ALG_ECDSA_SHA, false);
        //fnc_multiplication_x_keyAgreement = KeyAgreement.getInstance(Consts.KeyAgreement_ALG_EC_SVDP_DH_PLAIN_XY, false);
        fnc_multiplication_x_keyAgreement = KeyAgreement.getInstance(KeyAgreement_ALG_EC_SVDP_DH_PLAIN, false);
        fnc_SignVerifyECDSA_signEngine = Signature.getInstance(Signature_ALG_ECDSA_SHA_256, false);
        FLAG_FAST_EC_MULT_VIA_KA = true;
    } catch (Exception ignored) {
    } // Discard any exception        
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:15,代码来源:ECPoint_Helper.java

示例6: PRNGTest

import javacard.security.Signature; //导入依赖的package包/类
private PRNGTest() {
	random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);

	drngAESKey = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
			KeyBuilder.LENGTH_AES_128, false);

	tmp = JCSystem.makeTransientByteArray((short) 40,
			JCSystem.CLEAR_ON_DESELECT);

	random.generateData(tmp, (short) 0, (short) 16);
	drngAESKey.setKey(tmp, (short) 0);

	scratch = JCSystem.makeTransientByteArray((short) 32,
			JCSystem.CLEAR_ON_DESELECT);

	keyPair = new KeyPair((ECPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_256,false), 
			(ECPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_256, false));
	Secp256r1.setCommonCurveParameters((ECKey) keyPair.getPrivate());
	Secp256r1.setCommonCurveParameters((ECKey) keyPair.getPublic());

	

	// Initialize the unique key for DRNG function (AES CMAC)
	drngKey1 = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
			KeyBuilder.LENGTH_AES_128, false);
	drngKey2 = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
			KeyBuilder.LENGTH_AES_128, false);
	random.generateData(scratch, (short) 0, (short) 32);
	drngKey1.setKey(scratch, (short) 0);
	drngKey2.setKey(scratch, (short) 16);

	drng1 = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	drng1.init(drngKey1, Signature.MODE_SIGN);
	drng2 = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	drng2.init(drngKey2, Signature.MODE_SIGN);

	// Initialize the unique key for MAC function (AES CMAC)
	macKey = (AESKey) KeyBuilderX.buildKey(KeyBuilderX.TYPE_AES_STATIC,
			KeyBuilder.LENGTH_AES_128, false);
	random.generateData(scratch, (short) 0, (short) 16);
	macKey.setKey(scratch, (short) 0);

	cmacSign = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	cmacSign.init(macKey, Signature.MODE_SIGN);

	cmacVerify = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	cmacVerify.init(macKey, Signature.MODE_VERIFY);

	// Initialize ecMultiplier
	ecMultiplyHelper = KeyAgreementX.getInstance(KeyAgreementX.ALG_EC_SVDP_DH_PLAIN_XY, false);
}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:52,代码来源:PRNGTest.java

示例7: handleGetCmac

import javacard.security.Signature; //导入依赖的package包/类
private void handleGetCmac(APDU apdu) {
	byte[] buffer = apdu.getBuffer();
	short dataLen = apdu.setIncomingAndReceive();
	short dataOffset = apdu.getOffsetCdata();

	if (dataLen != 32) {
		ISOException.throwIt(ISO7816.SW_WRONG_DATA);
	}
	cmac = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
	cmac.init(drngAESKey, Signature.MODE_SIGN);
	short sigLen = cmac
			.sign(buffer, dataOffset, dataLen, buffer, (short) 0);
	apdu.setOutgoingAndSend((short) 0, sigLen);

}
 
开发者ID:tsenger,项目名称:CCU2F,代码行数:16,代码来源:PRNGTest.java

示例8: setSessionKeyMAC

import javacard.security.Signature; //导入依赖的package包/类
/**
 * Set the MAC session key. Each key is a 16 byte 3DES EDE key. This method 
 * may be called at any time and will immediately replace the session key.
 * 
 * @param buffer byte array containing the session key.
 * @param offset location of the session key in the buffer.
 */
public void setSessionKeyMAC(byte[] buffer, short offset) {
	// Check for empty keys
	if(Util.arrayCompare(buffer, (short)0, EMPTY_KEY, (short)0, KEY_SIZE) == 0) {
		keyMAC.clearKey();
		keyENC.clearKey();
	}
	else {     	
		keyMAC.setKey(buffer, offset);
    
		signer.init(keyMAC, Signature.MODE_SIGN);
		verifier.init(keyMAC, Signature.MODE_VERIFY);
	}
}
 
开发者ID:jderuiter,项目名称:javacard-openpgpcard,代码行数:21,代码来源:OpenPGPSecureMessaging.java

示例9: CryptonitApplet

import javacard.security.Signature; //导入依赖的package包/类
protected CryptonitApplet(byte[] bArray, short bOffset, byte bLength) {
    mgmt_key = KeyBuilder.buildKey(KeyBuilder.TYPE_DES,
            KeyBuilder.LENGTH_DES3_3KEY, false);
    ((DESKey) mgmt_key).setKey(new byte[]{
        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
    }, (short) 0);
    mgmt_counter = new OwnerPIN(MGMT_MAX_TRIES, (byte) 4);
    mgmt_counter.update(new byte[]{0x00, 0x00, 0x00, 0x00}, (short) 0, (byte) 4);

    challenge = JCSystem.makeTransientByteArray((short) 8,
            JCSystem.CLEAR_ON_DESELECT);

    pin = new OwnerPIN(PIN_MAX_TRIES, PIN_MAX_LENGTH);
    pin.update(new byte[]{
        0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38
    }, (short) 0, (byte) 8);

    keys = new Key[(byte) 4];
    random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
    authenticated = JCSystem.makeTransientBooleanArray((short) 1, JCSystem.CLEAR_ON_DESELECT);
    rsa_cipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);
    try {
        ec_signature = Signature.getInstance(Signature.ALG_ECDSA_SHA, false);
    } catch (Exception e) {
    }
    FileIndex index = new FileIndex();
    io = new IOBuffer(index);
    register();
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:32,代码来源:CryptonitApplet.java

示例10: getSignature

import javacard.security.Signature; //导入依赖的package包/类
private Signature getSignature(byte key_nb, byte alg_id) {
	if (signatures[key_nb] == null) {
		try {
			signatures[key_nb] = Signature.getInstance(alg_id, false);
		} catch (Exception e) {
			ISOException.throwIt(((CardRuntimeException) e).getReason());
		}
	} else if (signatures[key_nb].getAlgorithm() != alg_id)
		ISOException.throwIt(SW_OPERATION_NOT_ALLOWED);
	return signatures[key_nb];
}
 
开发者ID:Toporin,项目名称:SatoChipApplet,代码行数:12,代码来源:CardEdge.java

示例11: SecureMessaging

import javacard.security.Signature; //导入依赖的package包/类
/**
 * Constructor
 * 
 * @param _tempBuffer a reference for Transient byte array buffer that is used for intermediate operations 
 */
public SecureMessaging(byte[] _tempBuffer) {
	tempBuffer = _tempBuffer;

	mEncryptionKey = (AESKey) KeyBuilder.buildKey(
			KeyBuilder.TYPE_AES_TRANSIENT_DESELECT,
			KeyBuilder.LENGTH_AES_256, false);

	mMackey_1 = (AESKey) KeyBuilder.buildKey(
			KeyBuilder.TYPE_AES_TRANSIENT_DESELECT,
			KeyBuilder.LENGTH_AES_128, false);

	mMackey_2 = (AESKey) KeyBuilder.buildKey(
			KeyBuilder.TYPE_AES_TRANSIENT_DESELECT,
			KeyBuilder.LENGTH_AES_128, false);

	// iv = new byte[(short)0x10];

	mAESCipher = Cipher.getInstance(Cipher.ALG_AES_BLOCK_128_CBC_NOPAD,
			false);

	msgDigest_SHA256 = MessageDigest.getInstance(MessageDigest.ALG_SHA_256,
			false);

	mSignature = Signature.getInstance(Signature.ALG_AES_MAC_128_NOPAD,
			false);

}
 
开发者ID:mobilesec,项目名称:secure-channel-ec-srp-applet,代码行数:33,代码来源:SecureMessaging.java

示例12: computeChecksum_CMAC_with_AES_CBC_Signature

import javacard.security.Signature; //导入依赖的package包/类
/**
 * Calculates MAC over input using AES-CMAC-128 according to RFC 4493 
 * 
 * <p>
 * The last block to this input is always padded as specified in ETSI TS 102 176-2. 
 * Therefore only one Mac subkey is used for XORing the last block. 
 *  
 * @param input  byte array buffer containing the data over which MAC is computed
 * @param offset offset of data in the input buffer
 * @param length length of the data
 * @param output output byte array buffer
 * @param outOffset offset in the output for MAC value
 */

public void computeChecksum_CMAC_with_AES_CBC_Signature(byte[] input,
		short offset, short length, byte[] output, short outOffset) {
	if (length % BLOCK_SIZE != 0) {
		// exception incorrect input block size
		return;
	}
	if (ssc == (short) 0x0fff) {
		// exception max counter ... re-establish secure session
		return;
	}
	ssc++;
	Util.setShort(tempBuffer, OFFSET_SEND_SEQUENCE_COUNTER, ssc);
	
 	mSignature.init(mMackey_1, Signature.MODE_SIGN, tempBuffer,
 			OFFSET_ZERO_IV, BLOCK_SIZE);

	short len = (short) (length - BLOCK_SIZE);
	short i = 0;
	short lastBlockOffset = (short) (offset + len);
	/**
	 * save copy of the last block before modifying
	 */
	Util.arrayCopy(input, lastBlockOffset, output, (short)(outOffset + (short)0x10), BLOCK_SIZE);
	while (i < BLOCK_SIZE) {
		input[(short) (lastBlockOffset + i)] = (byte) (input[(short) (lastBlockOffset + i)] ^ tempBuffer[(short) (OFFSET_MAC_KEY_2 + i)]);
		i++;
	}
  
	/**
	 * sign
	 */	
	 mSignature.sign(input, offset, length, output, outOffset);
	/**
	 * restore last block
	 */
	 Util.arrayCopy(input,(short)(outOffset + (short)0x10) , output, lastBlockOffset, BLOCK_SIZE);
}
 
开发者ID:mobilesec,项目名称:secure-channel-ec-srp-applet,代码行数:52,代码来源:SecureMessaging.java

示例13: computeChecksum_CBC_MAC_from_AES_CBCSignature

import javacard.security.Signature; //导入依赖的package包/类
/**
 * 
 *   N.B. This method is not used in the current implementation
 * 
 * Calculates MAC over input according to ETSI TS 102 176-2 - Which uses CBC
 * MAC with Encryption of Last Block constructed from AES CBC Signature and
 * AES Cipher for encrypting the last output is more efficient compared to
 * using using only AES Cipher
 * 
 * @param input
 * @param offset
 * @param length
 * @param output
 * @param outOffset
 */

public void computeChecksum_CBC_MAC_from_AES_CBCSignature(byte[] input,
		short offset, short length, byte[] output, short outOffset) {
	if (length % BLOCK_SIZE != 0) {
		// exception incorrect input block size
		return;
	}
	if (ssc == (short) 0x0fff) {
		// exception max counter ... re-establish secure session
		return;
	}
	ssc++;
	Util.setShort(tempBuffer, OFFSET_SEND_SEQUENCE_COUNTER, ssc);
	/**
	 * sign with CBC
	 */
	mSignature.init(mMackey_1, Signature.MODE_SIGN, tempBuffer,
			OFFSET_ZERO_IV, BLOCK_SIZE);
	
	mSignature.sign(input, offset, length, output, outOffset);
	/**
	 * encrypt the output with sub key 2
	 */
	mAESCipher.init(mMackey_2, Cipher.MODE_ENCRYPT, tempBuffer,
			OFFSET_ZERO_IV, BLOCK_SIZE);
	mAESCipher.doFinal(output, outOffset , BLOCK_SIZE, output, outOffset);

}
 
开发者ID:mobilesec,项目名称:secure-channel-ec-srp-applet,代码行数:44,代码来源:SecureMessaging.java

示例14: YkneoCurves

import javacard.security.Signature; //导入依赖的package包/类
public YkneoCurves() {
	brainpoolp256r1 = BrainpoolP256r1.newKeyPair();
	secp256r1 = SecP256r1.newKeyPair();
	brainpoolp320r1 = BrainpoolP320r1.newKeyPair();
	brainpoolp256t1 = BrainpoolP256t1.newKeyPair();
	secp256k1 = SecP256k1.newKeyPair();
	gost2001 = Gost2001.newKeyPair();
	frp256v1 = Frp256v1.newKeyPair();
	
	signature = Signature.getInstance(Signature.ALG_ECDSA_SHA, false);
}
 
开发者ID:Yubico,项目名称:ykneo-curves,代码行数:12,代码来源:YkneoCurves.java

示例15: deriveSeed

import javacard.security.Signature; //导入依赖的package包/类
public static void deriveSeed(byte seedLength) {
	if (Crypto.signatureHmac != null) {
		Crypto.keyHmac2.setKey(BITCOIN_SEED, (short)0, (short)BITCOIN_SEED.length);
		if ((LedgerWalletApplet.proprietaryAPI != null) && (LedgerWalletApplet.proprietaryAPI.hasHmacSHA512())) {
			LedgerWalletApplet.proprietaryAPI.hmacSHA512(Crypto.keyHmac2, LedgerWalletApplet.scratch256, (short)0, seedLength, LedgerWalletApplet.masterDerived, (short)0);
		}
		else {
			Crypto.signatureHmac.init(Crypto.keyHmac2, Signature.MODE_SIGN);
			Crypto.signatureHmac.sign(LedgerWalletApplet.scratch256, (short)0, seedLength, LedgerWalletApplet.masterDerived, (short)0);
		}
	}
	else {
		HmacSha512.hmac(BITCOIN_SEED, (short)0, (short)BITCOIN_SEED.length, LedgerWalletApplet.scratch256, (short)0, seedLength, LedgerWalletApplet.masterDerived, (short)0, LedgerWalletApplet.scratch256, (short)64);
	}
}
 
开发者ID:LedgerHQ,项目名称:ledger-javacard,代码行数:16,代码来源:Bip32.java


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