def _encrypt(self, text, _id): text = to_binary(text) tmp_list = [] tmp_list.append(to_binary(self.get_random_string())) length = struct.pack(b'I', socket.htonl(len(text))) tmp_list.append(length) tmp_list.append(text) tmp_list.append(to_binary(_id)) text = b''.join(tmp_list) text = PKCS7Encoder.encode(text) ciphertext = to_binary(self.cipher.encrypt(text)) return base64.b64encode(ciphertext)
def state_imgs(request, user, msg, data, step): with transaction.atomic(): tweets = TaskTweet.objects.select_for_update(skip_locked=True).filter( task__owner=user.user, new=True) if tweets.exists(): ids = tweets.values_list('tweet__images__id', flat=True) content = to_binary( settings.WECHAT_TOKEN + ','.join(map(lambda x: '' if x is None else str(x), ids))) cipher_text = views.imgs_cipher.encrypt( PKCS7Encoder.encode(content)) encoded = to_text(base64.b64encode(cipher_text)) url = request.build_absolute_uri( reverse('wechat_imgs', kwargs={'imgs': encoded})) tweets.update(new=False) return TextReply(content=url, message=msg), None else: return TextReply(content='还没有获取到照片,请稍后再试', message=msg), None
def _encrypt(self, text): text = to_binary(text) text = PKCS7Encoder.encode(text) ciphertext = to_binary(self.cipher.encrypt(text)) return base64.b64encode(ciphertext)
def encryptEx(cls, string): aes = AES.new(cls.key[:16], mode=AES.MODE_ECB) return base64.urlsafe_b64encode(aes.encrypt(PKCS7Encoder.encode(string)))
def encrypt(cls, string): aes = AES.new(cls.key[:16], mode=AES.MODE_ECB) return base64.encodestring(aes.encrypt(PKCS7Encoder.encode(string)))
# coding=utf-8 import os import json import urllib import base64 import qrcode as qr from Crypto.Cipher import AES from wechatpy.crypto.pkcs7 import PKCS7Encoder url_prefix = r'http://pacs.winning.com.cn/scan/bind?card=' key = 'WinningSoftPACSFilmReportService' aes = AES.new(key[:16], mode=AES.MODE_ECB) print PKCS7Encoder.encode('') print base64.encodestring(aes.encrypt(PKCS7Encoder.encode('123'))) class EncryptConf(object): key = 'WinningSoftPACSFilmReportService' @classmethod def encrypt(cls, string): aes = AES.new(cls.key[:16], mode=AES.MODE_ECB) return base64.encodestring(aes.encrypt(PKCS7Encoder.encode(string))) @classmethod def decrypt(cls, string): aes = AES.new(cls.key[:16], mode=AES.MODE_ECB) return PKCS7Encoder.decode(aes.decrypt(base64.decodestring(string)))