예제 #1
0
def FuzzyPoro():

    extractor = FuzzyExtractor(10, 2)  # (CharacterLength, ErrorAllowed)
    BiometricData = "0123456789"  # Sample Biometric Data
    # Create the key and the helper
    key, helper = extractor.generate(BiometricData)

    print('Your key is: %s' % (key))

    # Runs your generated key through TripleSec
    KeyForTripleSec = TripleSec(key)
    EncryptedPrivateKey = KeyForTripleSec.encrypt(
        b"ThisWouldBeYourPrivateKey")  # Encrypts your private key

    print('Your encrypted private key is: %s' % (EncryptedPrivateKey))

    # The second time you scan your fingerprint/biometric data
    KeyRecover = input("Enter your key:")

    KeyReturn = extractor.reproduce(KeyRecover,
                                    helper)  # Creates your original key

    print('Your recovered key is: %s' % (KeyReturn))

    # Runs your regenerated key through TripleSec
    ExtractedKey = TripleSec(KeyReturn)

    print('Your private key is: ')
    # Decodes your EncryptedPrivateKey with your regenerated encryption key
    print(ExtractedKey.decrypt(EncryptedPrivateKey).decode())
예제 #2
0
    def test_uninitialized_behavior(self):
        T = TripleSec()
        self._test_encrypt(T.encrypt, VECTOR['plaintext'], VECTOR['key'])
        self.assertEqual(T.decrypt(VECTOR['ciphertext'], VECTOR['key']), VECTOR['plaintext'])

        T = TripleSec(b'foo')
        self._test_encrypt(T.encrypt, VECTOR['plaintext'], VECTOR['key'])
        self.assertEqual(T.decrypt(VECTOR['ciphertext'], VECTOR['key']), VECTOR['plaintext'])
예제 #3
0
 def test_using_randomness(self):
     for version in _versions.keys():
         compatibility = version in {1, 3}
         T = TripleSec(key=b"YELLOW_SUBMARINE")
         pt = b"foobar"
         once = T.encrypt(pt, v=version, compatibility=compatibility)
         twice = T.encrypt(pt, v=version, compatibility=compatibility)
         self.assertNotEqual(once, twice)
         T = TripleSec(key=b"YELLOW_SUBMARINE")
         thrice = T.encrypt(pt, v=version, compatibility=compatibility)
         self.assertNotEqual(once, thrice)
         self.assertNotEqual(twice, thrice)
예제 #4
0
 def test_missing_key(self):
     T = TripleSec()
     regex = 'You didn\'t initialize TripleSec with a key'
     self.assertRaisesRegexp(TripleSecError, regex, lambda: T.encrypt(b'xxx'))
     self.assertRaisesRegexp(TripleSecError, regex, lambda: T.decrypt(b'xxx'))
     self.assertRaisesRegexp(TripleSecError, regex, lambda: triplesec.encrypt(b'xxx'))
     self.assertRaisesRegexp(TripleSecError, regex, lambda: triplesec.decrypt(b'xxx'))
예제 #5
0
    def test_spec(self):
        for version in _versions.keys():
            compatibility = version in {1, 3}
            path = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
            with open(os.path.join(path, "spec/triplesec_v{}.json".format(version))) as specfile:
                vectors = json.load(specfile)
                for v in vectors['vectors']:
                    key = unhex(v['key'])
                    pt = unhex(v['pt'])
                    ct = unhex(v['ct'])
                    rndstream = six.BytesIO(unhex(v['r']))

                    # Self-consistency
                    got_self_compat = triplesec.encrypt(pt, key, compatibility=compatibility)
                    self.assertEqual(pt, triplesec.decrypt(got_self_compat, key, compatibility=compatibility))

                    # Self-consistency for reverse compatibility
                    got_self_rev_compat = triplesec.encrypt(pt, key, compatibility=not compatibility)
                    self.assertEqual(pt, triplesec.decrypt(got_self_rev_compat, key, compatibility=not compatibility))

                    # Able to decrypt spec
                    self.assertEqual(pt, triplesec.decrypt(ct, key, compatibility=compatibility))

                    # Correct encryption with fixed random tape
                    T = TripleSec(key, rndstream=rndstream)
                    got = T.encrypt(pt, v=version, compatibility=compatibility)
                    self.assertEqual(hexlify(got), hexlify(ct))
예제 #6
0
 def test_initialized_behavior(self):
     T = TripleSec(VECTOR['key'])
     self._test_encrypt(T.encrypt,
                        VECTOR['plaintext'],
                        VECTOR['key'],
                        pass_key=False)
     self.assertEqual(T.decrypt(VECTOR['ciphertext']), VECTOR['plaintext'])
예제 #7
0
 def test_data_type(self):
     T = TripleSec(VECTOR['key'])
     regex = r'The input data needs to be a binary string'
     for d in (u'xxx', 12, [12, 13]):
         self.assertRaisesRegexp(TripleSecError, regex,
                                 lambda: T.decrypt(d))
         self.assertRaisesRegexp(TripleSecError, regex,
                                 lambda: T.encrypt(d))
예제 #8
0
 def test_key_type(self):
     regex = r'The key needs to be a binary string'
     for k in (u'xxx', 12, [12, 13]):
         self.assertRaisesRegexp(TripleSecError, regex,
                                 lambda: TripleSec(k))
         self.assertRaisesRegexp(TripleSecError, regex,
                                 lambda: triplesec.decrypt(b'foo', k))
         self.assertRaisesRegexp(TripleSecError, regex,
                                 lambda: triplesec.encrypt(b'foo', k))
예제 #9
0
def FuzzyPoro():

    extractor = FuzzyExtractor(10, 3)  # (CharacterLength, ErrorAllowed)
    # Sample Biometric Data
    BiometricData = input("Enter biometric data (10 characters):")
    BiometricData = BiometricData.encode('utf-8')
    PrivateKey = input("Enter your private key:")
    PrivateKey = PrivateKey.encode('utf-8')
    # Create the key and the helper
    key, helper = extractor.generate(BiometricData)

    print('Your key is: %s' % (key))

    # Runs your generated key through TripleSec
    KeyForTripleSec = TripleSec(key)
    EncryptedPrivateKey = KeyForTripleSec.encrypt(
        PrivateKey)  # Encrypts your private key

    # Writes a local file with your encrypted private key in it. This file
    #gets uploaded to IPFS and you get to keep a local backup. You can delete it if you want.
    FileWrite = open("EncryptedKey.txt", "w+")
    FileWrite.write(str(EncryptedPrivateKey))
    FileWrite.close()

    print('Your encrypted private key is: %s' % (EncryptedPrivateKey))

    # The second time you scan your fingerprint/biometric data
    KeyRecover = input("Enter your biometric data again:")
    KeyReturn = extractor.reproduce(KeyRecover,
                                    helper)  # Creates your original key

    print('Your recovered key is: %s' % (KeyReturn))

    # Runs your regenerated key through TripleSec
    ExtractedKey = TripleSec(KeyReturn)

    try:
        print('Your private key is: ')

        # Decodes your EncryptedPrivateKey with your regenerated encryption key
        print(ExtractedKey.decrypt(EncryptedPrivateKey).decode())
    except:
        print('Wrong encryption key :(')
예제 #10
0
 def test_extra_bytes(self):
     extra_vectors = tuple(v for v in vectors if 'extra' in v)
     self.assertTrue(len(extra_vectors))
     for VECTOR in extra_vectors:
         T = TripleSec()
         self._test_encrypt(T.encrypt, VECTOR['plaintext'], VECTOR['key'])
         self.assertEqual(None, T.extra_bytes())
         data = VECTOR['ciphertext']
         header_version = struct.unpack(">I", data[4:8])[0]
         version = triplesec.versions.get_version(header_version, False)
         header, salt, macs, encrypted_material = T._split_ciphertext(data, version)
         mac_keys, cipher_keys, extra = T._key_stretching(VECTOR['key'], salt, version, len(VECTOR['extra']))
         self.assertEqual(VECTOR['extra'], extra)
         T.encrypt(VECTOR['plaintext'], VECTOR['key'], extra_bytes=len(VECTOR['extra']))
         self.assertTrue(T.extra_bytes())
         self._test_encrypt(T.encrypt, VECTOR['plaintext'], VECTOR['key'])
         self.assertEqual(None, T.extra_bytes())
예제 #11
0
def FuzzyPoro():

    extractor = FuzzyExtractor(10, 2)  # (CharacterLength, ErrorAllowed)
    # Sample Biometric Data
    BiometricData = input("Enter a biometric data (10 characters):")
    BiometricData = BiometricData.encode('utf-8')
    PrivateKey = input("Enter your private key:")
    PrivateKey = PrivateKey.encode('utf-8')
    # Create the key and the helper
    key, helper = extractor.generate(BiometricData)

    print ('Your key is: %s' % (key))

    # Runs your generated key through TripleSec
    KeyForTripleSec = TripleSec(key)
    EncryptedPrivateKey = KeyForTripleSec.encrypt(
        PrivateKey)  # Encrypts your private key
예제 #12
0
    FileWrite = open("EncryptedKey.txt", "w+")
    FileWrite.write(str(EncryptedPrivateKey))
    FileWrite.close()

    print ('Your encrypted private key is: %s' % (EncryptedPrivateKey))

    # The second time you scan your fingerprint/biometric data
    KeyRecover = input("Enter your biometric data again:")

    KeyReturn = extractor.reproduce(
        KeyRecover, helper)  # Creates your original key

    print ('Your recovered key is: %s' % (KeyReturn))

    # Runs your regenerated key through TripleSec
    ExtractedKey = TripleSec(KeyReturn)

    try:
        print ('Your private key is: ')

        # Decodes your EncryptedPrivateKey with your regenerated encryption key
        print(ExtractedKey.decrypt(EncryptedPrivateKey).decode())
    except:
        print ('Wrong encryption key BAD BAD BAD')


def IPFS():
    try:
        api = ipfsapi.connect('127.0.0.1', 5001)
        print(api)
예제 #13
0
from triplesec import TripleSec
from fuzzy_extractor import FuzzyExtractor


def FuzzyPoro():

        extractor = FuzzyExtractor(10, 2)  # (CharacterLength, ErrorAllowed)
        # Sample Biometric Data
        BiometricData = raw_input("Enter a biometric data (10 characters):")
        PrivateKey = raw_input("Enter your private key:")
        # Create the key and the helper
        key, helper = extractor.generate(BiometricData)

    print ('Your key is: %s' % (key))

        KeyForTripleSec = TripleSec(key) #Runs your generated key through TripleSec
        EncryptedPrivateKey = KeyForTripleSec.encrypt(PrivateKey) #Encrypts your private key

    print ('Your encrypted private key is: %s' % (EncryptedPrivateKey))

        KeyRecover = input("Enter your key:") #The second time you scan your fingerprint/biometric data

        KeyReturn = extractor.reproduce(KeyRecover, helper) #Creates your original key

    print ('Your recovered key is: %s' % (KeyReturn))

        ExtractedKey = TripleSec(KeyReturn) #Runs your regenerated key through TripleSec

        try:     
                        print ('Your private key is: ')