python能解密java的_python中的base64加密和解密

import base64

import json

def row_data():

content = {

"buyer_nick": "家有亲亲",

"payment": "109.40",

"status": "ok",

"iid": 0,

"oid": 76491699395733780,

"tid": "654561321213",

"type": "guarantee_trade",

"post_fee": "0.00",

"seller_nick": "测试店铺"

}

context_str = json.dumps(content, ensure_ascii=False)

d = {

"TmcId": 654561321213,

"Topic": "taobao_trade_TradeBuyerPay",

"UserId": "123456789",

"UserNick": "测试店铺",

"PubAppKey": "12345678",

"PubTime": "2017-10-18T16:32:39.033",

"OutgoingTime": "2017-10-18T16:32:39.237",

"Content": context_str

}

return d

class Base64Handler:

@classmethod

def base_encode(cls, json_data: dict):

data_to_str = json.dumps(json_data, ensure_ascii=False)

r = base64.b64encode(bytes(data_to_str, "utf-8"))

return str(r, encoding="utf-8")

@classmethod

def base64_decode(cls, s):

decode_data = base64.b64decode(s).decode()

return decode_data

encode_data = Base64Handler.base_encode(row_data())

print("encode data:\n{}".format(encode_data))

decode_data = Base64Handler.base64_decode(encode_data)

print("decode data:\n{}".format(decode_data))

# base64在线加解密网站: https://www.sojson.com/base64.html

"""

encode data:

eyJUbWNJZCI6IDY1NDU2MTMyMTIxMywgIlRvcGljIjogInRhb2Jhb190cmFkZV9UcmFkZUJ1eWVyUGF5IiwgIlVzZXJJZCI6ICIxMjM0NTY3ODkiLCAiVXNlck5pY2siOiAi5rWL6K+V5bqX6ZO6IiwgIlB1YkFwcEtleSI6ICIxMjM0NTY3OCIsICJQdWJUaW1lIjogIjIwMTctMTAtMThUMTY6MzI6MzkuMDMzIiwgIk91dGdvaW5nVGltZSI6ICIyMDE3LTEwLTE4VDE2OjMyOjM5LjIzNyIsICJDb250ZW50IjogIntcImJ1eWVyX25pY2tcIjogXCLlrrbmnInkurLkurJcIiwgXCJwYXltZW50XCI6IFwiMTA5LjQwXCIsIFwic3RhdHVzXCI6IFwib2tcIiwgXCJpaWRcIjogMCwgXCJvaWRcIjogNzY0OTE2OTkzOTU3MzM3ODAsIFwidGlkXCI6IFwiNjU0NTYxMzIxMjEzXCIsIFwidHlwZVwiOiBcImd1YXJhbnRlZV90cmFkZVwiLCBcInBvc3RfZmVlXCI6IFwiMC4wMFwiLCBcInNlbGxlcl9uaWNrXCI6IFwi5rWL6K+V5bqX6ZO6XCJ9In0=

decode data:

{"TmcId": 654561321213, "Topic": "taobao_trade_TradeBuyerPay", "UserId": "123456789", "UserNick": "测试店铺", "PubAppKey": "12345678", "PubTime": "2017-10-18T16:32:39.033", "OutgoingTime": "2017-10-18T16:32:39.237", "Content": "{\"buyer_nick\": \"家有亲亲\", \"payment\": \"109.40\", \"status\": \"ok\", \"iid\": 0, \"oid\": 76491699395733780, \"tid\": \"654561321213\", \"type\": \"guarantee_trade\", \"post_fee\": \"0.00\", \"seller_nick\": \"测试店铺\"}"}

"""

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值