def test_hashing_PyNaCl(self): from PQencryption.hashing import sha_512_hashlib from PQencryption.hashing import sha_512_PyNaCl salt = "a" * 128 message = "This is a message. Hash me!" hashed_PyNaCl = sha_512_PyNaCl.sha512_hash(salt, message) self.assertEqual( hashed_PyNaCl, "ab90b1da9cd3a8625a75a0e0aaaa5c7a14ab9dde9006d23cacac665cc0edbc9309d8cc715aaf715cbcad61e9ddb32eac785881e880bff32c22108cb58cf6a8bf" )
def example_hashing_PyNaCl(): from PQencryption.hashing import sha_512_PyNaCl # In production the salt should come from a hardware random number generator # and will be shared between parties. # Salt must be 128 bytes in hex. salt = "a" * 128 message = "This is a message. Hash me!" print(message) hashed = sha_512_PyNaCl.sha512_hash(salt, message) print(hashed) # make sure all memory is flushed after operations del salt del message gc.collect()
# ["housenum", "zipcode", "date_of_birth", "sex"] # act_data = act_data.drop(input['internal_id'], axis=1) # 2.3 PI columns (personal identifier) hashedPI = [] if df[PI].isnull().sum().sum() == 0: for i in range(0, len(df)): combine_PI = str() for j in range(0, len(PI)): id_feature = df.iloc[i][PI[j]] combine_PI = combine_PI + str(id_feature) # Remove space from strings # combine_PI = combine_PI.replace(' ', '') hashed = sha_512_PyNaCl.sha512_hash(salt, combine_PI.encode('UTF-8')) hashedPI.append(hashed) else: print( "Work cannot be done because missing values are in personal identifiers!" ) print(df.isnull().sum()) # print(len(hashedPI)) hashedPI_df = pd.DataFrame(hashedPI, columns=['encString']) hashedData_df = pd.concat([hashedPI_df, act_data], axis=1, join='inner') print(len(hashedData_df)) hashedData_df.to_csv("/data/encrypted_%s.csv" % (input['party_name']), index=None,