我有一个包含300列的df,但是我想加密一列 ID ,并且如果我将df作为csv的话,则允许其他人使用密钥解密.
I have a df with 300 columns but there is one column ID that I want to encrypt and allow anyone else with a key to decrypt if I give them the df as a csv.
这可能吗?
我知道如何对列进行哈希处理,但是据我所知,我无法对其进行哈希处理,也无法为某人提供对其进行哈希处理的密钥.
I know how to hash a column, but as far as I have read I can not unhash it or give someone a key to unhash it.
先谢谢您.
df id 1 2 3@Wen是一个很好的例子:
@Wen is this a good example:
(1:2), (2:3),(3:4)新df
id 2 3 4 推荐答案我建议使用python itsdangerous 库.这是一个简单的示例:
I'd recommend the python itsdangerous library. Here is a quick example:
from itsdangerous import URLSafeSerializer s = URLSafeSerializer('secret-key') print(s.dumps([1, 2, 3, 4])) # 'WzEsMiwzLDRd.wSPHqC0gR7VUqivlSukJ0IeTDgo' print(s.loads('WzEsMiwzLDRd.wSPHqC0gR7VUqivlSukJ0IeTDgo')) # [1, 2, 3, 4]秘密密钥可以在您和另一信任方之间共享,以解密字符串或列.
The secret-key can be shared between you and the other trusted party to decrypt the strings or columns.
这确实依赖于序列化,但是有些python数据类型不容易序列化,但是如果您只需要列名或类似的名称,则可以很好地工作.
This does rely on serialization however and some python data types aren't easily serialized, but if you just need a column name or something like that, this could work well.
更多推荐
如何使用解密密钥对 pandas 数据帧进行加密和解密?
发布评论