第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Python AES-CTR 與 Golang 不兼容

Python AES-CTR 與 Golang 不兼容

藍(lán)山帝景 2021-09-25 10:08:59
我在 Ubuntu 16.04 上使用 Python2.7 和 pycryptodome 3.6.6 和 Golang1.10.4。我選擇的加密算法是 AES-CTR-128。但是Python和Golang加密的數(shù)據(jù)卻有不同的結(jié)果。所以這兩種語(yǔ)言編寫(xiě)的應(yīng)用程序之間的通信存在問(wèn)題。這是我的實(shí)現(xiàn):Python:#coding=utf-8from __future__ import absolute_importimport binasciifrom Crypto.Cipher import AESfrom Crypto.Util import Counterdef hexlify(binary):    return binascii.hexlify(binary)class AES_CTR(object):    def __init__(self, key, iv):        assert len(key) == 16        assert len(iv) == 16        ctr = Counter.new(128)        self.aes = AES.new(key, AES.MODE_CTR, counter=ctr)    def encrypt(self, plain_data):        return self.aes.encrypt(plain_data)    def decrypt(self, encrypted_data):        return self.aes.decrypt(encrypted_data)if __name__ == '__main__':    aes = AES_CTR('abcdef0123456789', '0123456789abcdef')    print hexlify(aes.encrypt("hello")) #print '9b1a038478'    print hexlify(aes.encrypt("hello")) #print '8751ea0448'    print hexlify(aes.encrypt("world")) #print 'b6aa7c286b'高朗package mainimport (    "crypto/aes"    "crypto/cipher"    "encoding/hex"    "fmt")type AESCipher struct {    iv []byte    stream cipher.Stream}func NewAESCipher(key []byte, iv []byte) *AESCipher {    if (len(iv) != 16 || len(key) != 16) {        panic("iv length or key length error")    }    block, err := aes.NewCipher(key)    if (err != nil) {        panic(err)    }    return &AESCipher {        iv: iv,        stream: cipher.NewCTR(block, iv),    }}func (cipher *AESCipher) Encrypt(buffer []byte) []byte {    encrypted := make([]byte, len(buffer))    cipher.stream.XORKeyStream(encrypted, buffer)    return encrypted}func (cipher *AESCipher) Decrypt(buffer []byte) []byte {    decrypted := make([]byte, len(buffer))    cipher.stream.XORKeyStream(decrypted, buffer)    return decrypted}
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 299 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)