예제 #1
0
    def to_pem(self, pem_format='PKCS8'):

        if isinstance(self._prepared_key, pyrsa.PrivateKey):
            der = self._prepared_key.save_pkcs1(format='DER')
            if pem_format == 'PKCS8':
                pem = pyrsa_pem.save_pem(PKCS8_RSA_HEADER + der, pem_marker='PRIVATE KEY')
            elif pem_format == 'PKCS1':
                pem = pyrsa_pem.save_pem(der, pem_marker='RSA PRIVATE KEY')
            else:
                raise ValueError("Invalid pem format specified: %r" % (pem_format,))
        else:
            if pem_format == 'PKCS8':
                asn_key = AsnPubKey()
                asn_key.setComponentByName('modulus', self._prepared_key.n)
                asn_key.setComponentByName('publicExponent', self._prepared_key.e)
                der = encoder.encode(asn_key)

                header = PubKeyHeader()
                header['oid'] = univ.ObjectIdentifier('1.2.840.113549.1.1.1')
                pub_key = OpenSSLPubKey()
                pub_key['header'] = header
                pub_key['key'] = univ.BitString.fromOctetString(der)

                der = encoder.encode(pub_key)
                pem = pyrsa_pem.save_pem(der, pem_marker='PUBLIC KEY')
            elif pem_format == 'PKCS1':
                der = self._prepared_key.save_pkcs1(format='DER')
                pem = pyrsa_pem.save_pem(der, pem_marker='RSA PUBLIC KEY')
            else:
                raise ValueError("Invalid pem format specified: %r" % (pem_format,))
        return pem
예제 #2
0
파일: key.py 프로젝트: PostHttp/Diplom
    def _save_pkcs1_der(self):
        '''Saves the public key in PKCS#1 DER format.

        @returns: the DER-encoded public key.
        '''

        from pyasn1.codec.der import encoder
        from rsa.asn1 import AsnPubKey

        # Create the ASN object
        asn_key = AsnPubKey()
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)

        return encoder.encode(asn_key)
예제 #3
0
파일: key.py 프로젝트: Natsukikinb/XMLY
    def _save_pkcs1_der(self):
        """Saves the public key in PKCS#1 DER format.
        :returns: the DER-encoded public key.
        :rtype: bytes
        """

        from pyasn1.codec.der import encoder
        from rsa.asn1 import AsnPubKey

        # Create the ASN object
        asn_key = AsnPubKey()
        asn_key.setComponentByName('modulus', self.n)
        asn_key.setComponentByName('publicExponent', self.e)

        return encoder.encode(asn_key)
예제 #4
0
def ca():
    lock_InformationPipe.acquire()
    c = pipe.pop()
    writeOutputFile('Commitment received from user: '******'ascii')
    writeOutputFile('r_ca has been established: ' + r_ca.hex())

    #----------------------------> send r_ca to user
    pipe.append(r_ca)
    writeOutputFile('r_ca sent to user --------->')
    writeOutputFile('')
    lock_InformationPipe.release()
    time.sleep(3)

    #----------------------------> waiting proof, N, j
    lock_InformationPipe.acquire()

    proof_w = pipe.pop()
    writeOutputFile('Proof from user: '******'j from user: '******'p from user: '******'p from user: '******'modulus', p * q)
        asnPK.setComponentByName('publicExponent', e)

        pipe.append(True)
        writeOutputFile('golberg Proof: valid.')
        writeOutputFile('OK sent to user --------->')
        lock_InformationPipe.release()

        return asnPK

    writeOutputFile('golberg Proof: Not valid. Error sent to user --------->')
    pipe.append(False)
    lock_InformationPipe.release()

    raise_exception(Exception("golberg Proof: Not valid"))
예제 #5
0
 def RSAVP1(key:AsnPubKey, s:int)-> int:
     if s<0 or s >  key.getComponentByName('modulus')-1:
         raise ValueError("signature representative out of range")
     return (s**key.getComponentByName('publicExponent')) %  key.getComponentByName('modulus')