示例#1
0
EncryptKey
RsaAlgorithm::deriveEncryptKey(const Blob& keyBits)
{
  TpmPrivateKey privateKey;
  privateKey.loadPkcs8(keyBits.buf(), keyBits.size());
  return EncryptKey(privateKey.derivePublicKey());
}
// ClientCDKey::AsString
// Returns encrypted binary form of CD-Key.  Builds binary form if needed.
const RawBuffer&
ClientCDKey::AsBinary() const
{
	WTRACE("ClientCDKey::AsBinary");
	if (mBinKey.empty())
	{
		if (IsValid())
			EncryptKey(BufferFromFields());
		else
			mBinKey.erase();
	}

	return mBinKey;
}
// 更新出厂KEY
int ks_zjvcc_cardtype::UpdateKey(const byte ucMainKey[16],byte ucKeyIndex,byte ucKeyType,byte ucKey[16]) {
    int nRet=0;
    byte ucCmd[256]= {0};
    byte ucCmdLen=0;
    byte ucOutBuf[128]= {0};
    int  iOutLen=0;
    int  keylen = 0;
    byte ucMac[4]= {0};
    byte ucSessionKey[17]= {0};
    byte ucRandom[9]= {0};
    byte ucPlainKey[40]= {0};


    // 更新握奇出厂卡的密钥
    memcpy(ucCmd,"\x84\xD4\x00\x00\x1C",5);
    ucCmd[2] = ucKeyType;
    ucCmd[3] = ucKeyIndex;

    keylen = 0;
    ucPlainKey[keylen++] = 16;
    memcpy(ucPlainKey+keylen,ucKey,16);
    keylen += 16;
    memcpy(ucPlainKey+keylen,"\x80\x00\x00\x00\x00\x00\x00",7);
    keylen += 7;

    nRet=GetRandomNum8(ucRandom);
    if(nRet) {
        return nRet;
    }

    //用主控会话密钥加密待加密数据
    EncryptKey(ucMainKey,2,ucPlainKey,keylen,ucOutBuf,iOutLen);

    memcpy(ucCmd+5,ucOutBuf,iOutLen);
    ucCmdLen=iOutLen+5;

    // 计算MAC
    CalcMac(ucRandom,(byte*)ucMainKey,2,ucCmd,ucCmdLen,ucMac);

    memcpy(ucCmd+ucCmdLen,ucMac,4);
    ucCmdLen+=4;

    byte ucRespData[256]= {0};
    byte ucRespLen = 0;

    return Adpu(ucCmd,ucCmdLen, ucRespData, ucRespLen);
}
示例#4
0
 /**
  * Derive a new encrypt key from the given decrypt key value.
  * @param keyBits The key value of the decrypt key.
  * @return The new encrypt key.
  */
 static EncryptKey
 deriveEncryptKey(const Blob& keyBits)
 {
   return EncryptKey(keyBits);
 }