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


Python CryptoUtils.get_cipher_keylen方法代码示例

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


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

示例1: __init__

# 需要导入模块: from virtualsmartcard import CryptoUtils [as 别名]
# 或者: from virtualsmartcard.CryptoUtils import get_cipher_keylen [as 别名]
    def __init__(self, PIN, cardNumber, mf=None, cardSecret=None, default_se=Security_Environment):

        self.PIN = PIN
        self.mf = mf
        self.cardNumber = cardNumber

        self.last_challenge = None #Will contain non-readable binary string
        self.counter = 3 #Number of tries for PIN validation

        self.cipher = 0x01
        self.asym_key = None
        
        keylen = vsCrypto.get_cipher_keylen(get_referenced_cipher(self.cipher))
        if cardSecret is None: #Generate a random card secret
            self.cardSecret = urandom(keylen)
        else:
            if len(cardSecret) != keylen:
                raise ValueError("cardSecret has the wrong key length for: " +\
                    get_referenced_cipher(self.cipher))
            else:
                self.cardSecret = cardSecret  

        #Security Environments may be saved to/retrieved from this dictionary
        self.saved_SEs = {} 
        self.default_se = default_se
        self.current_SE = default_se(self.mf, self)
开发者ID:12019,项目名称:vsmartcard,代码行数:28,代码来源:SmartcardSAM.py

示例2: _get_referenced_key

# 需要导入模块: from virtualsmartcard import CryptoUtils [as 别名]
# 或者: from virtualsmartcard.CryptoUtils import get_cipher_keylen [as 别名]
    def _get_referenced_key(self, p1, p2):
        """
        This method returns the key specified by the p2 parameter. The key may
        be stored on the cards filesystem.

        :param p1: Specifies the algorithm to use. Needed to know the keylength.
        :param p2: Specifies a reference to the key to be used for encryption

            == == == == == == == == =============================================
            b8 b7 b6 b5 b4 b3 b2 b1 Meaning
            == == == == == == == == =============================================
            0  0  0  0  0  0  0  0  No information is given
            0  -  -  -  -  -  -  -  Global reference data(e.g. MF specific key)
            1  -  -  -  -  -  -  -  Specific reference data(e.g. DF specific key)
            -  -  -  x  x  x  x  x  Number of the secret
            == == == == == == == == =============================================

            Any other value RFU
        """
        
        key = None
        qualifier = p2 & 0x1F
        algo = get_referenced_cipher(p1)        
        keylength = vsCrypto.get_cipher_keylen(algo)

        if (p2 == 0x00): #No information given, use the global card key
            key = self.cardSecret
        #We treat global and specific reference data alike
        #elif ((p2 >> 7) == 0x01 or (p2 >> 7) == 0x00):
        else:		
            #Interpret qualifier as an short fid (try to read the key from FS)
            if self.mf == None:
                raise SwError(SW["ERR_REFNOTUSABLE"])
            df = self.mf.currentDF()
            fid = df.select("fid", stringtoint(qualifier))
            key = fid.readbinary(keylength)

        if key != None:
            return key
        else: 
            raise SwError(SW["ERR_REFNOTUSABLE"])
开发者ID:12019,项目名称:vsmartcard,代码行数:43,代码来源:SmartcardSAM.py


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