django中加解密如下:
def decode_pubkey(getpub): # 解码公钥
public_key_bytes = base64.b64decode(getpub)
server_public_key = serialization.load_der_public_key(
public_key_bytes,
backend=default_backend()
)
# print(server_public_key)
return server_public_key
def date_encode(getpub, original_string):
original_string_bytes = original_string.encode("utf-8")
ciphertext = decode_pubkey(getpub).encrypt(
original_string_bytes,
padding.PKCS1v15()
)
encrypted_data_string = base64.b64encode(ciphertext).decode('utf-8')
# print("Encrypted data:", encrypted_data_string)
return encrypted_data_string
def date_decode(encode_str, private_key_str):
private_key_bytes = base64.b64decode(private_key_str)
ciphertext_bytes = base64.b64decode(encode_str)
private_key = serialization.load_der_private_key(
private_key_bytes,
password=None,
backend=default_backend()
)
plaintext = private_key.decrypt(
ciphertext_bytes,
padding.PKCS1v15()
)
plaintext1 = plaintext.decode('utf-8')
return plaintext1
公私钥转化为der格式,前端vue中该怎么进行加解密,对传递到django数据加密,拿到django传回来的数据进行解密