Reputation: 91
I am trying to encrypt data and send it over a TCP socket to my server. However I am getting the error, ValueError: Key must be 128 bit long for the code below:
from xtea import *
from socket import *
import datetime
import time
import sys
clientsocket = socket(AF_INET,SOCK_STREAM)
clientsocket.connect(("xx.xx.xx.xx",1234))
key2="0wYwcOnn"
text = "$123456781|tx|id1^1.1^2015-09-29 16:38:44^2015-09-29 19:48:44"
x = new(key2, mode=MODE_ECB)
c = x.encrypt(text)
clientsocket.send(c)
recv = clientsocket.recv(1024)
print(recv)
Can anyone please comment on this?
Upvotes: 0
Views: 429
Reputation: 21583
XTEA requires a 128bit (16 bytes) key.
one possible padding scheme for keys that are less than 16 bytes long, is to simply pad it with null bytes until it's 16 bytes. according to the guy Wooble
at irc://irc.freenode.net/#python , this should work:
key2=struct.pack('16s', b"0wYwcOnn")
Upvotes: 0
Reputation: 112875
Increase the key size to 16-bytes.
XTEA is a 64-bit block Feistel cipher with a 128-bit key. Since "0wYwcOnn"
is 64 bits (at best) what is the misunderstanding?
Upvotes: 1