JAVA Cipher 加密C 语言无法解密问题总结

AES算法(DES等其余算法一样)。AES算法有各类格局CBC/ECB/CFB/OFB,那各样Java和C都有落实。AES算法还会有最终的填写,java扶助的padding格局有三种NoPadding/PKCS5Padding/,而C却无法显式的安装padding格局,暗许的padding就是在末尾加
‘\0’。那是贰个西贡市,多少人都坑在那了。其它,网络海人民广播广播台湾大学JAVA
AES算法,相当多都用SecureRandom,假如你的代码中出现了SecureRandom那么些东西,那么您再也不能用C解出来了。

Aes 加密三种办法为啥加出来的区别样?求大神疏解

c语言 文件加密难点
一、文件加密
对音讯举办加密,可增加音讯传输的安全性。正是由于它的主要性用途,大家发明了美妙绝伦的加密方法。当中一种艺术是,对文中单词举行逆序管理。请您写三个主次,对已加密的文件进行解密。
输入输出样例:
输入:
2
eno owt eerht
i ekil siht emag

率先看secret.cpp的代码结合“From:”来扩充切入。

/*********************************************************
 *  des.h
 *  用户使用des算法头文件
 *    
 *********************************************************/
#ifndef _OPENDESS_H_
#define _OPENDESS_H_

#ifdef __cplusplus
extern "C" {
#endif

//ab\0defg

//用户使用的函数
int DesEnc(
        unsigned char *pInData,//明文
        int            nInDataLen,
        unsigned char *pOutData,//密文
        int           *pOutDataLen);

//用户使用函数des解密
int DesDec(
       unsigned char *pInData,//密文
       int            nInDataLen,
       unsigned char *pOutData,//明文
       int           *pOutDataLen);

#ifdef __cplusplus
}
#endif

#endif

/******************************************************
 *
 *  des.c
 *  common des......
 *
 ******************************************************/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "des.h"

/*********************************************************
  data type definition for Des;
**********************************************************/
#define EN0    0
#define DE1    1

#define DES_KEYBYTES    128
#define DES_KEYLONGS    32
#define DES_BLOCKLEN    8

typedef struct {
    unsigned char ek[DES_KEYBYTES];
    int    ekLen;
    unsigned char dk[DES_KEYBYTES];
    int    dkLen;
    unsigned char CbcCtx[DES_BLOCKLEN];
} DES_CTX;

typedef struct {
    unsigned char ek1[DES_KEYBYTES];
    int    ek1Len;
    unsigned char dk1[DES_KEYBYTES];
    int    dk1Len;
    unsigned char ek2[DES_KEYBYTES];
    int    ek2Len;
    unsigned char dk2[DES_KEYBYTES];
    int    dk2Len;
    unsigned char CbcCtx[DES_BLOCKLEN];
    //int    IsFirstBlock;
} DES3_CTX;


static unsigned char pc1[56] = {
    56, 48, 40, 32, 24, 16,  8,  0, 57, 49, 41, 33, 25, 17,
     9,  1, 58, 50, 42, 34, 26, 18, 10,  2, 59, 51, 43, 35,
    62, 54, 46, 38, 30, 22, 14,  6, 61, 53, 45, 37, 29, 21,
    13,  5, 60, 52, 44, 36, 28, 20, 12,  4, 27, 19, 11,  3 };

static unsigned char pc2[48] = {
    13, 16, 10, 23,  0,  4,         2, 27, 14,  5, 20,  9,
    22, 18, 11,  3, 25,  7,     15,  6, 26, 19, 12,  1,
    40, 51, 30, 36, 46, 54,        29, 39, 50, 44, 32, 47,
    43, 48, 38, 55, 33, 52,     45, 41, 49, 35, 28, 31 };

static unsigned short bytebit[8] = {0200,0100,040,020,010,04,02,01 };
static unsigned char totrot[16] = {1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28};
static unsigned long bigbyte[24] = {
    0x800000L,    0x400000L,    0x200000L,    0x100000L,
    0x80000L,    0x40000L,    0x20000L,    0x10000L,
    0x8000L,    0x4000L,    0x2000L,    0x1000L,
    0x800L,        0x400L,        0x200L,        0x100L,
    0x80L,        0x40L,        0x20L,        0x10L,
    0x8L,        0x4L,        0x2L,        0x1L    };

//insert digits
static unsigned long SP1[64] ={
       0x01010400l,0x00000000l,0x00010000l,0x01010404l,
       0x01010004l,0x00010404l,0x00000004l,0x00010000l,
       0x00000400l,0x01010400l,0x01010404l,0x00000400l,
       0x01000404l,0x01010004l,0x01000000l,0x00000004l,
       0x00000404l,0x01000400l,0x01000400l,0x00010400l,
       0x00010400l,0x01010000l,0x01010000l,0x01000404l,
       0x00010004l,0x01000004l,0x01000004l,0x00010004l,
       0x00000000l,0x00000404l,0x00010404l,0x01000000l,
       0x00010000l,0x01010404l,0x00000004l,0x01010000l,
       0x01010400l,0x01000000l,0x01000000l,0x00000400l,
       0x01010004l,0x00010000l,0x00010400l,0x01000004l,
       0x00000400l,0x00000004l,0x01000404l,0x00010404l,
       0x01010404l,0x00010004l,0x01010000l,0x01000404l,
       0x01000004l,0x00000404l,0x00010404l,0x01010400l,
       0x00000404l,0x01000400l,0x01000400l,0x00000000l,
       0x00010004l,0x00010400l,0x00000000l,0x01010004l };


static unsigned long SP2[64]={
       0x80108020l,0x80008000l,0x00008000l,0x00108020l,
       0x00100000l,0x00000020l,0x80100020l,0x80008020l,
       0x80000020l,0x80108020l,0x80108000l,0x80000000l,
       0x80008000l,0x00100000l,0x00000020l,0x80100020l,
       0x00108000l,0x00100020l,0x80008020l,0x00000000l,
       0x80000000l,0x00008000l,0x00108020l,0x80100000l,
       0x00100020l,0x80000020l,0x00000000l,0x00108000l,
       0x00008020l,0x80108000l,0x80100000l,0x00008020l,
       0x00000000l,0x00108020l,0x80100020l,0x00100000l,
       0x80008020l,0x80100000l,0x80108000l,0x00008000l,
       0x80100000l,0x80008000l,0x00000020l,0x80108020l,
       0x00108020l,0x00000020l,0x00008000l,0x80000000l,
       0x00008020l,0x80108000l,0x00100000l,0x80000020l,
       0x00100020l,0x80008020l,0x80000020l,0x00100020l,
       0x00108000l,0x00000000l,0x80008000l,0x00008020l,
       0x80000000l,0x80100020l,0x80108020l,0x00108000l };


static unsigned long SP3[64]={ 
       0x00000208l,0x08020200l,0x00000000l,0x08020008l,
       0x08000200l,0x00000000l,0x00020208l,0x08000200l,
       0x00020008l,0x08000008l,0x08000008l,0x00020000l,
       0x08020208l,0x00020008l,0x08020000l,0x00000208l,
       0x08000000l,0x00000008l,0x08020200l,0x00000200l,
       0x00020200l,0x08020000l,0x08020008l,0x00020208l,
       0x08000208l,0x00020200l,0x00020000l,0x08000208l,
       0x00000008l,0x08020208l,0x00000200l,0x08000000l,
       0x08020200l,0x08000000l,0x00020008l,0x00000208l,
       0x00020000l,0x08020200l,0x08000200l,0x00000000l,
       0x00000200l,0x00020008l,0x08020208l,0x08000200l,
       0x08000008l,0x00000200l,0x00000000l,0x08020008l,
       0x08000208l,0x00020000l,0x08000000l,0x08020208l,
       0x00000008l,0x00020208l,0x00020200l,0x08000008l,
       0x08020000l,0x08000208l,0x00000208l,0x08020000l,
       0x00020208l,0x00000008l,0x08020008l,0x00020200l };


static unsigned long SP4[64]={             
       0x00802001l,0x00002081l,0x00002081l,0x00000080l,
       0x00802080l,0x00800081l,0x00800001l,0x00002001l,
       0x00000000l,0x00802000l,0x00802000l,0x00802081l,
       0x00000081l,0x00000000l,0x00800080l,0x00800001l,
       0x00000001l,0x00002000l,0x00800000l,0x00802001l,
       0x00000080l,0x00800000l,0x00002001l,0x00002080l,
       0x00800081l,0x00000001l,0x00002080l,0x00800080l,
       0x00002000l,0x00802080l,0x00802081l,0x00000081l,
       0x00800080l,0x00800001l,0x00802000l,0x00802081l,
       0x00000081l,0x00000000l,0x00000000l,0x00802000l,
       0x00002080l,0x00800080l,0x00800081l,0x00000001l,
       0x00802001l,0x00002081l,0x00002081l,0x00000080l,
       0x00802081l,0x00000081l,0x00000001l,0x00002000l,
       0x00800001l,0x00002001l,0x00802080l,0x00800081l,
       0x00002001l,0x00002080l,0x00800000l,0x00802001l,
       0x00000080l,0x00800000l,0x00002000l,0x00802080l };


static unsigned long SP5[64]={   
       0x00000100l,0x02080100l,0x02080000l,0x42000100l,
       0x00080000l,0x00000100l,0x40000000l,0x02080000l,
       0x40080100l,0x00080000l,0x02000100l,0x40080100l,
       0x42000100l,0x42080000l,0x00080100l,0x40000000l,
       0x02000000l,0x40080000l,0x40080000l,0x00000000l,
       0x40000100l,0x42080100l,0x42080100l,0x02000100l,
       0x42080000l,0x40000100l,0x00000000l,0x42000000l,
       0x02080100l,0x02000000l,0x42000000l,0x00080100l,
       0x00080000l,0x42000100l,0x00000100l,0x02000000l,
       0x40000000l,0x02080000l,0x42000100l,0x40080100l,
       0x02000100l,0x40000000l,0x42080000l,0x02080100l,
       0x40080100l,0x00000100l,0x20000000l,0x42080000l,
       0x42080100l,0x00080100l,0x42000000l,0x42080100l,
       0x02080000l,0x02000100l,0x40000100l,0x00080000l,
       0x00080100l,0x02000100l,0x40000100l,0x00080000l,
       0x00000000l,0x40080000l,0x02080100l,0x40000100l };


static unsigned long SP6[64]={ 
       0x20000010l,0x20400000l,0x00004000l,0x20404010l,
       0x20400000l,0x00000010l,0x20404010l,0x00400000l,
       0x20004000l,0x00404010l,0x00400000l,0x20000010l,
       0x00400010l,0x20004000l,0x20000000l,0x00004010l,
       0x00000000l,0x00400010l,0x20004010l,0x00004000l,
       0x00404000l,0x20004010l,0x00000010l,0x20400010l,
       0x20400010l,0x00000000l,0x00404010l,0x20404000l,
       0x00004010l,0x00404000l,0x20404000l,0x20000000l,
       0x20004000l,0x00000010l,0x20400010l,0x00404000l,
       0x20404010l,0x00400000l,0x00004010l,0x20000010l,
       0x00400000l,0x20004000l,0x20000000l,0x00004010l,
       0x20000010l,0x20404010l,0x00404000l,0x20400000l,
       0x00404010l,0x20404000l,0x00000000l,0x20400010l,
       0x00000010l,0x00004000l,0x20400000l,0x00404010l,
       0x00004000l,0x00400010l,0x20004010l,0x00000000l,
       0x20404000l,0x20000000l,0x00400010l,0x20004010l };  

static unsigned long SP7[64] = {
    0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,
    0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,
    0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,
    0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,
    0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,
    0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,
    0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,
    0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,
    0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,
    0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,
    0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,
    0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,
    0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,
    0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,
    0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,
    0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L };

static unsigned long SP8[64] = {
    0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,
    0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,
    0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,
    0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,
    0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,
    0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,
    0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,
    0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,
    0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,
    0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,
    0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,
    0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,
    0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,
    0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,
    0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,
    0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L };

void deskey(unsigned char *key,short edf, unsigned long *kn);
void cookey(register unsigned long *raw1, unsigned long *dough);
//void cpkey(register unsigned long *into);
//void usekey(register unsigned long *from);
//void des(unsigned char *inblock,unsigned char *outblock);
void scrunch(register unsigned char *outof, register unsigned long *into);
void unscrun(register unsigned long *outof, register unsigned char *into);
void desfunc(register unsigned long *block,register unsigned long *keys);

/*****************  DES Function  *****************/
unsigned long OPENCOMM_DesExpandEncKey(
        unsigned char *pbDesKey,
        unsigned long  ulDesKeyLen,
        unsigned char *pbDesEncKey,
        unsigned long *ulDesEncKeyLen);

unsigned long OPENCOMM_DesExpandDecKey(
        unsigned char *pbDesKey,
        unsigned long  ulDesKeyLen,
        unsigned char *pbDesDecKey,
        unsigned long *ulDesDecKeyLen);

unsigned long OPENCOMM_DesEncRaw(
        unsigned char *pbDesEncKey,
        unsigned long  ulDesEncKeyLen,
        unsigned char *pbInData,
        unsigned long  ulInDataLen,
        unsigned char *pbOutData,
        unsigned long *ulOutDataLen);

unsigned long OPENCOMM_DesDecRaw(
        unsigned char *pbDesDecKey,
        unsigned long  ulDesDecKeyLen,
        unsigned char *pbInData,
        unsigned long  ulInDataLen,
        unsigned char *pbOutData,
        unsigned long *ulOutDataLen);


int myic_DESDecrypt(
        unsigned char *pDesKey,
        int            nDesKeyLen,
        unsigned char *pInData,
        int            nInDataLen,
        unsigned char *pOutData,
        int           *pOutDataLen);

int myic_DESEncrypt(
        unsigned char *pDesKey,
        int            nDesKeyLen,
        unsigned char *pInData,
        int            nInDataLen,
        unsigned char *pOutData,
        int           *pOutDataLen);


void deskey(unsigned char *key,short edf, unsigned long *kn)
{
    register int i, j, l, m, n;
    unsigned long pc1m[56],pcr[56];


    for ( j = 0; j < 56; j++ ) 
    {
        l = pc1[j];
        m = l & 07;
        pc1m[j] = (((unsigned long) key[l >> 3] & (unsigned long)bytebit[m] ) ? 1:0);
    }
    for ( i = 0;i < 16; i++)
    {
        if ( edf == DE1 )    m = (15 - i) << 1;
        else    m = i << 1;
        n = m + 1;
        kn[m] = kn[n] = 0L;
        for ( j = 0; j < 28; j++ )
        {
            l = j + totrot[i];
            if ( l < 28 )    pcr[j] = pc1m[l];
            else    pcr[j] = pc1m[l-28];
        }
        for (j = 28; j < 56; j++ ) 
        {
            l = j + totrot[i];
            if ( l < 56 )    pcr[j] = pc1m[l];
            else    pcr[j] = pc1m[l-28];
        } 
        for ( j = 0; j < 24; j++ ) 
        {
            if ( pcr[pc2[j]] )    kn[m] |= bigbyte[j];
            if ( pcr[pc2[j+24]] )    kn[n] |= bigbyte[j];
        }
    }
    return;
}

void cookey(register unsigned long *raw1, unsigned long *dough)
{
    register unsigned long *cook,*raw0;
    register int i;

    cook = dough;
    for ( i = 0; i < 16; i++, raw1++ ) {
        raw0 = raw1++;
        *cook     = (*raw0 & 0x00fc0000L) << 6;
        *cook    |= (*raw0 & 0x00000fc0L) << 10;
        *cook    |= (*raw1 & 0x00fc0000L) >> 10;
        *cook++    |= (*raw1 & 0x00000fc0L) >> 6;
        *cook     = (*raw0 & 0x0003f000L) << 12;
        *cook    |= (*raw0 & 0x0000003fL) << 16;
        *cook    |= (*raw1 & 0x0003f000L) >> 4;
        *cook++    |= (*raw1 & 0x0000003fL);
    }
    return;
}

void scrunch(register unsigned char *outof, register unsigned long *into)
{
    *into     = (*outof++ & 0xffL) << 24;
    *into    |= (*outof++ & 0xffL) << 16;
    *into    |= (*outof++ & 0xffL) << 8;
    *into++    |= (*outof++ & 0xffL);
    *into     = (*outof++ & 0xffL) << 24;
    *into    |= (*outof++ & 0xffL) << 16;
    *into    |= (*outof++ & 0xffL) << 8;
    *into++    |= (*outof   & 0xffL);
    return;
}

void unscrun(register unsigned long *outof, register unsigned char *into)
{
    *into++     = (unsigned char)((*outof >> 24) & 0xffL);
    *into++     = (unsigned char)((*outof >> 16) & 0xffL);
    *into++     = (unsigned char)((*outof >>  8) & 0xffL);
    *into++     = (unsigned char)( *outof++      & 0xffL);
    *into++     = (unsigned char)((*outof >> 24) & 0xffL);
    *into++     = (unsigned char)((*outof >> 16) & 0xffL);
    *into++     = (unsigned char)((*outof >>  8) & 0xffL);
    *into     = (unsigned char)( *outof          & 0xffL);
    return;
}

void desfunc(register unsigned long *block,register unsigned long *keys)
{
    register unsigned long fval, work, right, leftt;
    register int round;

    leftt = block[0];
    right = block[1];
    work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;

    right ^= work;
    leftt ^= (work << 4);
    work = ((leftt >> 16) ^ right) & 0x0000ffffL;

    right ^= work;
    leftt ^= (work << 16);
    work = ((right >> 2) ^ leftt) & 0x33333333L;

    leftt ^= work;
    right ^= (work << 2);
    work = ((right >> 8) ^ leftt) & 0x00ff00ffL;

    leftt ^= work;
    right ^= (work << 8);
    right = ((right << 1) | ((right >>31) & 1L)) & 0xffffffffL;
    work = (leftt ^ right) & 0xaaaaaaaaL;

    leftt ^= work;
    right ^= work;
    leftt = ((leftt << 1) | ((leftt >> 31)&1L)) & 0xffffffffL;

    for (round = 0; round < 8; round++) {
        work  = (right << 28) | (right >> 4);
        work ^= *keys++;
        fval  = SP7[ work    & 0x3fL];
        fval |= SP5[(work >>  8) & 0x3fL];
        fval |= SP3[(work >> 16) & 0x3fL];
        fval |= SP1[(work >> 24) & 0x3fL];
        work  = right ^ *keys++;
        fval |= SP8[ work     & 0x3fL];
        fval |= SP6[(work >>  8) & 0x3fL];
        fval |= SP4[(work >> 16) & 0x3fL];
        fval |= SP2[(work >> 24) & 0x3fL];
        leftt ^= fval;
        work  = (leftt << 28) | (leftt >> 4);
        work ^= *keys++;
        fval  = SP7[ work     & 0x3fL];
        fval |= SP5[(work >>  8) & 0x3fL];
        fval |= SP3[(work >> 16) & 0x3fL];
        fval |= SP1[(work >> 24) & 0x3fL];
        work  = leftt ^ *keys++;
        fval |= SP8[ work     & 0x3fL];
        fval |= SP6[(work >>  8) & 0x3fL];
        fval |= SP4[(work >> 16) & 0x3fL];
        fval |= SP2[(work >> 24) & 0x3fL];
        right ^= fval;
    }

    right = (right << 31) | (right >> 1);
    work = (leftt ^ right) & 0xaaaaaaaaL;
    leftt ^= work;
    right ^= work;
    leftt = (leftt << 31) | (leftt >> 1);
    work = ((leftt >>  8) ^ right) & 0x00ff00ffL;
    right ^= work;
    leftt ^= (work << 8);
    work = ((leftt >>  2) ^ right) & 0x33333333L;
    right ^= work;
    leftt ^= (work << 2);
    work = ((right >> 16) ^ leftt) & 0x0000ffffL;
    leftt ^= work;
    right ^= (work << 16);
    work = ((right >>  4) ^ leftt) & 0x0f0f0f0fL;
    leftt ^= work;
    right ^= (work << 4);
    *block++ = right;
    *block = leftt;
    return;
}

/*****************************************************************
    OPENCOMM_DesExpandEncKey    : Expand Des Enc Key 扩展des加密密钥
    Return value:
        0         : Success
        other     : failed
    Parameters:
        pbDesKey        : 扩展前的DES密钥(8字节)       input
        ulDesKeyLen     : 扩展前的DES密钥长度          input
        pbDesEncKey     : 扩展后的DES加密密钥(128字节)  output
        *ulDesEncKeyLen : 扩展后的DES加密密钥长度       output
*****************************************************************/
unsigned long OPENCOMM_DesExpandEncKey(
        unsigned char *pbDesKey,
        unsigned long  ulDesKeyLen,
        unsigned char *pbDesEncKey,
        unsigned long *ulDesEncKeyLen)
{
    unsigned long kn[32], dough[32];

    if (ulDesKeyLen != 8)
        return 0xEE20;

    deskey(pbDesKey, EN0, kn);
    cookey(kn, dough);
    *ulDesEncKeyLen = DES_KEYBYTES;  //32 long = 128 bytes
    memcpy(pbDesEncKey, dough, *ulDesEncKeyLen);

    return 0;
}

/*****************************************************************
    OPENCOMM_DesExpandDecKey    : Expand Des Dec Key 扩展des解密密钥
    Return value:
        0       : Success
        other   : failed
    Parameters:
        pbDesKey        : 扩展前的DES密钥(8字节)      input
        ulDesKeyLen     : 扩展前的DES密钥长度         input
        pbDesDecKey     : 扩展后的DES解密密钥(128字节) output
        *ulDesDecKeyLen : 扩展后的DES解密密钥长度      output
*****************************************************************/
unsigned long OPENCOMM_DesExpandDecKey(
        unsigned char *pbDesKey,
        unsigned long  ulDesKeyLen,
        unsigned char *pbDesDecKey,
        unsigned long *ulDesDecKeyLen)
{
    unsigned long kn[32], dough[32];

    if (ulDesKeyLen != 8)
        return 0xEE20;

    deskey(pbDesKey, DE1, kn);
    cookey(kn, dough);
    *ulDesDecKeyLen = DES_KEYBYTES;  //32 long = 128 bytes
    memcpy(pbDesDecKey, dough, *ulDesDecKeyLen);

    return 0;
}

/****************************************************************
    OPENCOMM_DesEncRaw        : Des算法加密小整块明文8字节 
    Return value:
        0       : Success
        other   : failed
    Parameters:
        pbDesEncKey    : DES加密密钥    input
        ulDesEncKeyLen : DES加密密钥长度 input
        pbInData       : 待加密的明文    input
        ulInDataLen    : 待加密的明文长度 input
        pbOutData      : 加密后的密文    output
        *ulOutDataLen  : 加密后的密文长度 output
*****************************************************************/
unsigned long OPENCOMM_DesEncRaw(
        unsigned char *pbDesEncKey,
        unsigned long  ulDesEncKeyLen,
        unsigned char *pbInData,
        unsigned long  ulInDataLen,
        unsigned char *pbOutData,
        unsigned long *ulOutDataLen)
{
    unsigned long work[2], ek[DES_KEYLONGS];
    unsigned char cp[DES_BLOCKLEN];

    if (ulInDataLen != DES_BLOCKLEN)
        return 0xEE20;

    if (ulDesEncKeyLen != DES_KEYBYTES)
        return 0xEE20;

    memcpy(cp, pbInData, DES_BLOCKLEN);
    scrunch(cp,work);  // 8 bytes -> 2 long
    memcpy(ek, pbDesEncKey, ulDesEncKeyLen);
    desfunc(work,ek);
    unscrun(work,cp); // 2 long -> 8 bytes
    memcpy(pbOutData, cp, DES_BLOCKLEN);
    *ulOutDataLen = DES_BLOCKLEN;

    return 0;
}

/*****************************************************************
    OPENCOMM_DesDecRaw : Des算法解密小整块密文8字节 
    Return value:
        0     : Success
        other : failed
    Parameters:
        pbDesDecKey    : DES解密密钥     input
        ulDesDecKeyLen : DES解密密钥长度  input
        pbInData       : 待解密的密文     input
        ulInDataLen    : 待解密的密文长度  input
        pbOutData      : 解密后的明文     output
        *ulOutDataLen  : 解密后的明文长度  output
*****************************************************************/
unsigned long OPENCOMM_DesDecRaw(
        unsigned char *pbDesDecKey,
        unsigned long  ulDesDecKeyLen,
        unsigned char *pbInData,
        unsigned long  ulInDataLen,
        unsigned char *pbOutData,
        unsigned long *ulOutDataLen)
{
    unsigned long work[2], dk[DES_KEYLONGS];
    unsigned char cp[DES_BLOCKLEN];

    if (ulInDataLen != DES_BLOCKLEN)
        return 0xEE20;

    if (ulDesDecKeyLen != DES_KEYBYTES)
        return 0xEE20;

    memcpy(cp, pbInData, DES_BLOCKLEN);
    scrunch(cp,work);  // 8 bytes -> 2 long
    memcpy(dk, pbDesDecKey, ulDesDecKeyLen);
    desfunc(work,dk);
    unscrun(work,cp); // 2 long -> 8 bytes
    memcpy(pbOutData, cp, DES_BLOCKLEN);
//    des_enc(pbDesEncKey, pbInData, pbOutData);
    *ulOutDataLen = DES_BLOCKLEN;

    return 0;
}

/*********************   DES    *********************/

int myic_DESEncrypt(
        unsigned char *pDesKey,
        int            nDesKeyLen,
        unsigned char *pInData,
        int            nInDataLen,
        unsigned char *pOutData,
        int           *pOutDataLen)
{
    unsigned char DesKeyBuf[32];
    unsigned char DesEncKeyBuf[128];
    int EncKeyLen, KeyLen = 0;
    int retval = 0, loops, i;

    if(nInDataLen%8 != 0)
        return 0xEE20;

    if(nDesKeyLen != 8)
        return 0xEE20;
    KeyLen = nDesKeyLen;
    memcpy(DesKeyBuf, pDesKey, nDesKeyLen);


    retval = OPENCOMM_DesExpandEncKey(DesKeyBuf, KeyLen,
        DesEncKeyBuf, (unsigned long *)&EncKeyLen);
    if(retval != 0)
        return retval;

    loops = nInDataLen/8;
    for(i = 0; i < loops; i++)
    {
        retval = OPENCOMM_DesEncRaw(DesEncKeyBuf, EncKeyLen, pInData + i*8,
            8, pOutData + i*8, (unsigned long *)pOutDataLen);
        if(retval != 0)
            return retval;
    }
    *pOutDataLen = nInDataLen;
    return retval;
}


int myic_DESDecrypt(
        unsigned char *pDesKey,
        int            nDesKeyLen,
        unsigned char *pInData,
        int            nInDataLen,
        unsigned char *pOutData,
        int           *pOutDataLen)
{
    unsigned char DesKeyBuf[32];
    unsigned char DesDecKeyBuf[128];
    int DecKeyLen, KeyLen = 0;
    int retval = 0, loops, i;

    if(nInDataLen%8 != 0)
        return 0xEE20;

    if(nDesKeyLen != 8)
        return 0xEE20;
    KeyLen = nDesKeyLen;
    memcpy(DesKeyBuf, pDesKey, nDesKeyLen);

    retval = OPENCOMM_DesExpandDecKey(DesKeyBuf, KeyLen,
        DesDecKeyBuf, (unsigned long *)&DecKeyLen);
    if(retval != 0)
        return retval;

    loops = nInDataLen/8;
    for(i = 0; i < loops; i++)
    {
        retval = OPENCOMM_DesDecRaw(DesDecKeyBuf, DecKeyLen, pInData + i*8,
            8, pOutData + i*8, (unsigned long *)pOutDataLen);
        if(retval != 0)
            return retval;
    }
    *pOutDataLen = nInDataLen;
    return retval;
}


//对称明文数据打pading
void  CW_dataPadAdd(int tag, unsigned char *date, unsigned int dateLen, 
                    unsigned char **padDate, unsigned int *padDateLen)
{
    int           i, padLen;
    unsigned char *pTmp   = NULL;

    pTmp = (unsigned char *)malloc(dateLen+24);
    if (pTmp == NULL)
    {
        *padDate = NULL;
        return ;
    }
    memset(pTmp, 0, dateLen+24);
    memcpy(pTmp, date, dateLen);

    if (tag == 0)
    {
        padLen = 8 - dateLen % 8;
        for (i=0; i<padLen; i++)
        {
            pTmp[dateLen+i] = (char)padLen;
        }
        *padDateLen = dateLen + padLen;
    }
    else
    {
        padLen = 16 - dateLen % 16;
        for (i=0; i<padLen; i++)
        {
            pTmp[dateLen+i] = (char)padLen;
        }        
    }

    *padDateLen = dateLen + padLen;    
    *padDate = pTmp;
}

#define  USER_PASSWORD_KEY "abcd1234"


//数据加密
int DesEnc(
         unsigned char *pInData,
         int            nInDataLen,
         unsigned char *pOutData,
         int           *pOutDataLen)
{
    int                rv;
    unsigned char    *padDate = NULL;
    unsigned int    padDateLen = 0;

    CW_dataPadAdd(0, pInData, (unsigned int )nInDataLen, &padDate, &padDateLen);

    rv = myic_DESEncrypt((unsigned char *)USER_PASSWORD_KEY, strlen(USER_PASSWORD_KEY),
        padDate, (int)padDateLen, pOutData, pOutDataLen);
    if (rv != 0)
    {
        if (padDate != NULL)
        {
            free(padDate);
        }
        return rv;    
    }

    if (padDate != NULL)
    {
        free(padDate);
    }
    return 0;
}


//数据加密
int DesEnc_raw(
    unsigned char *pInData,
    int            nInDataLen,
    unsigned char *pOutData,
    int           *pOutDataLen)
{
    int                rv;
    unsigned char    *padDate = NULL;
    unsigned int    padDateLen = 0;

    rv = myic_DESEncrypt((unsigned char *)USER_PASSWORD_KEY, strlen(USER_PASSWORD_KEY),
        pInData, (int)nInDataLen, pOutData, pOutDataLen);
    if (rv != 0)
    {
        return rv;    
    }
    return 0;
}

//解密分配内存错误
#define  ERR_MALLOC 20
//密码长度不是8的整数倍, 不合法
#define  ERR_FILECONT 20


//用户使用函数des解密
int DesDec(
           unsigned char *pInData,
           int            nInDataLen,
           unsigned char *pOutData,
           int           *pOutDataLen)
{
    int                rv;
    char            padChar;
    unsigned char     *tmpPlain = NULL;

    tmpPlain =        (unsigned char *)malloc(nInDataLen+24);
    if (tmpPlain == NULL)
    {
        return ERR_MALLOC;
    }
    memset(tmpPlain, 0, nInDataLen+24);

    //解密
    rv = myic_DESDecrypt((unsigned char *)USER_PASSWORD_KEY, strlen(USER_PASSWORD_KEY),
        pInData, nInDataLen, tmpPlain, pOutDataLen);
    if (rv != 0)
    {
        if (tmpPlain != NULL) free(tmpPlain);
        return rv;
    }

    //去pading
    padChar = tmpPlain[*pOutDataLen - 1];
    if ( (int)padChar<=0 || (int)padChar>8) //异常处理
    {
        if (tmpPlain) free(tmpPlain);
        return ERR_FILECONT;
    }

    *pOutDataLen = *pOutDataLen - (int)padChar;    
    //memset(tmpPlain + *pOutDataLen, 0, (int)padChar);    
    memcpy(pOutData, tmpPlain, *pOutDataLen);
    if (tmpPlain) free(tmpPlain);    
    return 0;
}


//用户使用函数des解密
int DesDec_raw(
    unsigned char *pInData,
    int            nInDataLen,
    unsigned char *pOutData,
    int           *pOutDataLen)
{
    int                rv;
    //char            padChar;
    //unsigned char     *tmpPlain = NULL;

    /*
    tmpPlain =        (unsigned char *)malloc(nInDataLen+24);
    if (tmpPlain == NULL)
    {
        return ERR_MALLOC;
    }
    memset(tmpPlain, 0, nInDataLen+24);
    */

    //解密
    rv = myic_DESDecrypt((unsigned char *)USER_PASSWORD_KEY, strlen(USER_PASSWORD_KEY),
        pInData, nInDataLen, pOutData, pOutDataLen);
    if (rv != 0)
    {
        //if (tmpPlain != NULL) free(tmpPlain);
        return rv;
    }
    /*
    //去pading
    padChar = tmpPlain[*pOutDataLen - 1];
    if ( (int)padChar<=0 || (int)padChar>8) //异常处理
    {
        if (tmpPlain) free(tmpPlain);
        return ERR_FILECONT;
    }

    *pOutDataLen = *pOutDataLen - (int)padChar;    
    //memset(tmpPlain + *pOutDataLen, 0, (int)padChar);    
    memcpy(pOutData, tmpPlain, *pOutDataLen);
    if (tmpPlain) free(tmpPlain);    
    */
    return 0;
}

#define  _CRT_SECURE_NO_WARNINGS 
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "des.h"

int main11()
{
    int        ret = 0;
    char *plain = "1232343444";//明文
    int plainlen = strlen(plain);

    char plain2[4096] = {0};//明文
    int plainlen2 = 0;

    unsigned char cryptbuf[4096] = {0};//密文
    int cryptlen = 0;
    //用户使用的函数
    ret =  DesEnc(plain, plainlen, cryptbuf, &cryptlen);
    if (ret != 0)
    {
        printf("func DesEnc() err:%d \n");
        return ret;
    }

    //用户使用函数des解密
    ret =   DesDec(cryptbuf, cryptlen,  plain2, &plainlen2);
    if (ret != 0)
    {
        printf("func DesDec() err:%d \n");
        return ret;
    }

    if (plainlen != plainlen2)
    {
        ret = -2;
        printf("明文长度和解密后的明文长度 不一样 \n");
        return ret;
    }

    if (memcmp(plain2, plain, plainlen) == 0 )
    {
        printf("明文长度和解密后的明文长度 一样 ok \n");
    }
    else
    {
        printf("明文长度和解密后的明文长度 不一样 err \n");
    }

    system("pause");
    return ret ;
}

#define  _CRT_SECURE_NO_WARNINGS 
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "des.h"

int FileSymEnc(const char *pfile1, const char *pfile2)//pfile1输入文件,
{
    int        ret = 0;
    FILE *fp1= NULL, *fp2 = NULL;
    unsigned char plain[4096];
    int plainlen = 0;

    unsigned char cryptbuf[4096] = {0};
    int cryptlen = 0;

    int tmplen;

    fp1 = fopen(pfile1, "rb");//读的方式打开文件
    if (fp1 == NULL)
    {
        goto END;
    }

    fp2 = fopen(pfile2, "wb");//写的方式打开文件
    if (fp2 == NULL)
    {
        goto END;
    }

    while (!feof(fp1))//每次读取4k
    {
        plainlen = fread(plain, 1, 4096, fp1);//每次读取4k
        if (feof(fp1))  //读完数据以后,判断是否文件结束
        {
            break;//文件不足以4k,则跳出
        }

        //加密==4k的数据
        ret =  DesDec_raw(plain, plainlen, cryptbuf, &cryptlen);
        if (ret != 0)
        {
            printf("func DesEnc() err:%d \n", ret);
            goto END;
        }

        tmplen = fwrite(cryptbuf, 1, cryptlen, fp2);
        if (tmplen != cryptlen)//明文和密文的长度是一样的
        {
            ret  = -3;
            printf("写密文文件失败,请检查是否磁盘已满\n");
            goto END;
        }

        //if (plainlen == 4096)
    }

    //加密小于4k的数据
    ret =  DesEnc(plain, plainlen, cryptbuf, &cryptlen);
    if (ret != 0)
    {
        printf("func DesEnc() err:%d \n", ret);
        goto END;
    }

    tmplen = fwrite(cryptbuf, 1, cryptlen, fp2);
    if (cryptlen != tmplen)//磁盘已满
    {
        ret  = -3;
        printf("写小于4k文件密文失败,请检查是否磁盘已满\n");
        goto END;
    }

END:
    if (fp1 != NULL)
    {
        fclose(fp1);
    }
    if (fp2 != NULL)
    {
        fclose(fp2);
    }
    return 0;
}

void main()
{
    int        ret = 0;
    const char *file1 = "c:/socketclient.dll";
    const char *file2 = "c:/socketclientend.dll";

    //const char *file1 = "c:/22.txt";
    //const char *file2 = "c:/22enc.txt";

    ret =  FileSymEnc(file1, file2);
    if (ret != 0)
    {
        printf("func FileSymEnc() err\n " );
        return ;
    }

    system("pause");
    return ;
}

图片 1password.jpeg

第一种

输出:
one two three
i like this game

鉴于前边举行的都是宣称变量,变量赋值的行事,所以从第103行早先解析。

 

 1    /**
 2      * 加密
 3      * @param content
 4      * @param keyBytes
 5      * @param iv
 6      * @return
 7      * @throws Exception
 8      */
 9     public String AES_CBC_Encrypt(byte[] content, byte[] keyBytes, byte[] iv) throws Exception{
10         try{
11             KeyGenerator keyGenerator= KeyGenerator.getInstance("AES");
12             keyGenerator.init(128, new SecureRandom(keyBytes) );
13             SecretKey key=keyGenerator.generateKey();
14             Cipher cipher=Cipher.getInstance("AES/CBC/PKCS5Padding");
15             cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
16             byte[] result=cipher.doFinal(content);
17             return Base64.encodeBase64String(result);
18         }catch (Exception e) {
19             e.printStackTrace();
20             throw e;
21         }
22     }
23 
24     /**
25      * 解密
26      * @param content
27      * @param keyBytes
28      * @param iv
29      * @return
30      * @throws Exception
31      */
32     public String AES_CBC_Decrypt(byte[] content, byte[] keyBytes, byte[] iv) throws Exception{
33         try{
34 
35             KeyGenerator keyGenerator=KeyGenerator.getInstance("AES");
36             keyGenerator.init(128, new SecureRandom(keyBytes));//key长可设为128,192,256位,这里只能设为128
37             SecretKey key=keyGenerator.generateKey();
38             Cipher cipher=Cipher.getInstance("AES/CBC/PKCS5Padding");
39             cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
40 
41             byte[] result=cipher.doFinal(content);
42             return Base64.encodeBase64String(result);
43         }catch (Exception e) {
44             e.printStackTrace();
45             throw e;
46         }
47     }
#include<stdio.h>typedef struct{ char ch[1000]; int length;}SString;SString s[50000];int Decode(){// SString s[50000]; int a,b,N,i,j,k=0; char cs[1000]; scanf("%d",&N); if(N>50000) return 0; for(j=0;j<N;j++) { b=0; i=0; cs[i++]=getchar(); cs[i]=getchar(); while(cs[i]!='\n') { if(cs[i]==' ') { for(a=i-1;a>=b;a--) s[j].ch[k++]=cs[a]; s[j].ch[k++]=' '; i++; b=i; cs[i]=getchar(); } } s[j].length=i; } return N;} void print { int i,j; printf; for(j=0;j<n;j++) { for(i=0;i<s[j].length;i++) { printf("%c",s[j].ch[i]); } printf; } }void main(){ int i; i=Decode(); print;}

process_key12(int * key1,int *
key2)函数中*((int *) (key1 + *key1)) = *key2;代表了将*key1(实际变量存款和储蓄地方)的所在地方向高地址扩大
*key1
的偏移量处的值赋为key2的值。当然这和偏移量有关,所以未来还不亮堂特别值被修改了。

Cipher objects are obtained by using one of the Cipher getInstance()
static factory methods. Here, the algorithm name is slightly different
than with other engine classes, in that it specifies not just an
algorithm name, but a “transformation”. A transformation is a string
that describes the operation (or set of operations) to be performed on
the given input to produce some output. A transformation always includes
the name of a cryptographic algorithm (e.g., AES), and may be followed
by a mode and padding scheme.

 

那是笔者的顺序求助有何难题

三番五次向下看源码,开采start = 0, stride =1。

Cipher对象是经过行使Cipher getInstance()静态工厂方法获得的。这里,算法名称与其他引擎类略有分化,因为它不光钦赐算法名称,并且点名“转变”。转变是叙述要对给定输入实践的操作以发出某个输出的字符串。转变总是包蕴加密算法的名称,然后大概是形式和填充方案。

第二种

然后是process_key34(),查看代码后意识实类似的操作,先放着。

A transformation is of the form:

 1 /**
 2      * 提供密钥和向量进行加密
 3      *
 4      * @param sSrc
 5      * @param key
 6      * @param iv
 7      * @return
 8      * @throws Exception
 9      */
10     public static String Encrypt(String sSrc, byte[] key, byte[] iv) throws Exception {
11         SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
12         Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");// "算法/模式/补码方式"
13         IvParameterSpec _iv = new IvParameterSpec(iv);// 使用CBC模式,需要一个向量iv,可增加加密算法的强度
14         cipher.init(Cipher.ENCRYPT_MODE, skeySpec, _iv);
15         byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
16         return Base64.encodeBase64String(encrypted);
17     }
18     /**
19      * 提供密钥和向量进行解密
20      *
21      * @param sSrc
22      * @param key
23      * @param iv
24      * @return
25      * @throws Exception
26      */
27     public static String Decrypt(String sSrc, byte[] key, byte[] iv) throws Exception {
28         SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
29         Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
30         IvParameterSpec _iv = new IvParameterSpec(iv);
31         cipher.init(Cipher.DECRYPT_MODE, skeySpec, _iv);
32         byte[] encrypted = Base64.decodeBase64(sSrc);
33         byte[] original = cipher.doFinal(encrypted);
34         return new String(original, "utf-8");
35     }

接下来初始extract_message1(start, stride)密文的decode操作。将start =
0,stride =
1带代入,发现是一个死循环,所以那时start和stride的值并不对,那么哪些修改呢,发掘是process_key12()的熏陶,于是钻探此函数:

“algorithm/mode/padding” or”algorithm”For example, the following are
valid transformations:

 

  • 部分变量的转移顺序是dummy,start,stride,key1,key2,由于栈是从高地址向低地址进行分配的,所以*key是多个正数何况process函数只可以修改一个数的值而start和stride都由dummy来伊始决定,所以分明修改了dummy的值,所以key1的值为3(因为有dummy,start,stride七个4字节int值),接下去要求规定key2的值。
  • start = (int)(*(((char *) &dummy)));
    stride = (int)(*(((char *) &dummy) + 1));
    这两段是start的赋值,能够看见先转成char指针,在转成int值,而char占用1字节,int占用4字节,所以(_ _ _ _,表示dummy的几个字节,而前后相继里以字节为单位来逆序排列dummy的三个字节,如dummy=340,内部存款和储蓄器内dummy的字节种类是(低地址到高地址)15 04 00 00,由此能够看看,不止栈是从高地址向低地址来分配的,何况变量的字节是由高地址向低地址00000415读取的)。
  • 当今基于From:的ascii码值来找,发掘为46 72 6F 6D
    3A,然后在data中寻觅,注意data在内部存款和储蓄器中以4字节独一单位,四字节里边顺序是高地址向低地址读取,所以并不是原原本本的data中的那些顺序,并且data中的4字节是从最后多个开首压进栈中的。所以加法操作后到高地址,正好能够达到data后边的字节中。
  • 近年来来看for循环,i变量只是提供message[i]中i的效率,内部变量循环stride-1次,出来后又+1,今后来观察多少个字节出现的相继,后边的数值是离开*data的距离,即+j。
 "AES/CBC/PKCS5Padding" "AES"

If just a transformation name is specified, the system will determine if
there is an implementation of the requested transformation available in
the environment, and if there is more than one, returns there is a
preferred one.

46:  9 *10* 20
72:  *11* 12 21
6F:  *13* 15
6D:  *14* 19
3A:  *16*

If both a transformation name and a package provider are specified, the
system will determine if there is an implementation of the requested
transformation in the package requested, and throw an exception if there
is not.

能够看看里边循环为一回,所以stride=3,start = 10 -1
=9,所以key2=0x00000309=777.

It is recommended to use a transformation that fully specifies the
algorithm, mode, and padding. By not doing so, the provider will use a
default. For example, the SunJCE and SunPKCS11 providers uses ECB as
the default mode, and PKCS5Padding as the default padding for many
symmetric ciphers.

从此以往获得结果

This means that in the case of the SunJCE provider:

From: Friend
To: You
Good! Now try choosing keys3,4 to force a call to extract2 and
avoid the call to extract1
 Cipher c1 = Cipher.getInstance("AES/ECB/PKCS5Padding");

发觉还会有第二段密文,然大家用key3和key4来绕过extract1,所以必要改造process_key34之后的回到地址。

and

process_key34的函数进度为*(((int *)&key3) + *key3) += *key4;*key3为偏移量,此处&key3指的是形参中的key3,所以就和函数栈有关。大家明白形参是从右往左入栈的,而在形参入栈后,会把函数再次来到地址加上,所以函数再次来到地址是在key3的上面(低地址处),所以*key3的值为-1,所以函数的回来地址扩展加少技艺绕过exetract_message1呢,此时大家反汇编源程序,查看exetract_message1和exetract_message2的函数地址。

 Cipher c1 = Cipher.getInstance;
0x100000ead <+253>: callq  0x100000c10               ; process_keys34 at main.c:57
    0x100000eb2 <+258>: movl   -0x18(%rbp), %edi
    0x100000eb5 <+261>: movl   -0x1c(%rbp), %esi
    0x100000eb8 <+264>: callq  0x100000c40               ; extract_message1 at main.c:62
    0x100000ebd <+269>: movq   %rax, -0x38(%rbp)
    0x100000ec1 <+273>: movq   -0x38(%rbp), %rax
    0x100000ec5 <+277>: movsbl (%rax), %esi
    0x100000ec8 <+280>: cmpl   $0x0, %esi
    0x100000ece <+286>: jne    0x100000f0a               ; <+346> at main.c:128
    0x100000ed4 <+292>: leaq   -0x28(%rbp), %rdi
    0x100000ed8 <+296>: leaq   -0x2c(%rbp), %rsi
    0x100000edc <+300>: callq  0x100000c10               ; process_keys34 at main.c:57
    0x100000ee1 <+305>: movl   -0x18(%rbp), %edi
    0x100000ee4 <+308>: movl   -0x1c(%rbp), %esi
    0x100000ee7 <+311>: callq  0x100000d30               ; extract_message2 at main.c:82

are equivalent statements.

所以key4= 311 – 264 = 47。

因为暗中同意格局和暗中同意的对齐情势,上面的两条语句是等价的.

就算如此key3和key4带进去都未有赢得精确的值,可是笔者尽力了。~~

综上,key1 = 3,key2 = 777,key = -1,key4 = 47。

Cipher The algorithms are specified as transformations. Implementations
must support the key sizes in parentheses. AES/CBC/NoPadding

  • AES/CBC/PKCS5Padding
  • AES/ECB/NoPadding
  • AES/ECB/PKCS5Padding
  • DES/CBC/NoPadding
  • DES/CBC/PKCS5Padding
  • DES/ECB/NoPadding
  • DES/ECB/PKCS5Padding
  • DESede/CBC/NoPadding
  • DESede/CBC/PKCS5Padding
  • DESede/ECB/NoPadding
  • DESede/ECB/PKCS5Padding
  • RSA/ECB/PKCS1Padding (1024, 2048)
  • RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048)
  • RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048)

异构语言加解密在保险密钥一致的前题下,还要确认保证以上多个参数是一律的,对于密码和加密原著要注意添充情势,假若不未有落实,必要手动添充。

demo见下文

相关文章