lua des crypt padding兼容问题

152 views
Skip to first unread message

rei

unread,
Sep 25, 2015, 11:45:25 PM9/25/15
to skynet-users

lua des crypt 算法和java 的DES/ECB/PKCS5Padding模式不兼容,padding的填充模式需要调整下:
    int bytes = textsz - i;
    uint8_t tail[8];
    int j;
    for (j=0;j<8;j++) {
        if (j < bytes) {
            tail[j] = text[i+j];
        } else if (j==bytes) {
            tail[j] = 0x08 - bytes;
        } else {
            tail[j] = 0x08 - bytes;
        }
    }
    des_crypt(SK, tail, buffer+i);
缺几位填充几,在此记录下。

盐巴

unread,
Jan 4, 2018, 12:25:20 AM1/4/18
to skynet-users

des decode 的时候呢?
在 2015年9月26日星期六 UTC+8上午11:45:25,rei写道:

盐巴

unread,
Jan 4, 2018, 1:45:47 AM1/4/18
to skynet-users
int padding = buffer[textsz-1];

在 2015年9月26日星期六 UTC+8上午11:45:25,rei写道:
Reply all
Reply to author
Forward
0 new messages