OpenSSL之DES api语法初识

转载来源http://www.qmailer.net/archives/188.html

DES api:
1、数据结构:

typedef unsigned char DES_cblock[8];
typedef /* const */ unsigned char const_DES_cblock[8];

typedef struct DES_ks
{
    union
    {
        DES_cblock cblock;
        DES_LONG deslong[2];
    } ks[16];
} DES_key_schedule;

sizeof(DES_cblock) = 8字节
sizeof(const_DES_cblock ) = 8字节
sizeof(DES_key_schedule) = 128字节

2、基本宏定义

#define DES_ENCRYPT 1
#define DES_DECRYPT 0

3、设置密钥函数

//根据字符串生成key
void DES_string_to_key(const char *str, DES_cblock *key);

//will check that the key passed is of odd parity and is not a week or semi-weak key.
//If the parity is wrong, then -1 is returned. If the key is a weak key, then -2 is returned.
//If an error is returned, the key schedule is not generated
//设置密码表,并进行校验
int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);

//设置密码表,不需要校验
void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);

4、DES ECB模式加解密API

void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, DES_key_schedule *ks, int enc);

参数说明:
    input:输入数据,8字节
    output:输出数据,8字节
    ks:密钥
    enc:加密-DES_ENCRYPT,解密-DES_DECRYPT

5、DES CBC模式加解密API

void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output, long length, DES_key_schedule *schedule, DES_cblock *ivec, int enc);

参数说明:
    input: 输入参数,8字节倍数
    output: 输出参数,8字节倍数
    length: input的长度
    schedule: 密钥
    ivec: 初始向量, 8字节
    enc: 加密-DES_ENCRYPT,解密-DES_DECRYPT
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值