CN111314053B - 一种数据加密和解密方法 - Google Patents

一种数据加密和解密方法 Download PDF

Info

Publication number
CN111314053B
CN111314053B CN201811517780.1A CN201811517780A CN111314053B CN 111314053 B CN111314053 B CN 111314053B CN 201811517780 A CN201811517780 A CN 201811517780A CN 111314053 B CN111314053 B CN 111314053B
Authority
CN
China
Prior art keywords
ciphertext
sequence
shift
base64
confusion
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811517780.1A
Other languages
English (en)
Other versions
CN111314053A (zh
Inventor
刘红梅
陆长明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Lingjia Data Technology Co ltd
Original Assignee
Shanghai Lingjia Data Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Lingjia Data Technology Co ltd filed Critical Shanghai Lingjia Data Technology Co ltd
Priority to CN201811517780.1A priority Critical patent/CN111314053B/zh
Publication of CN111314053A publication Critical patent/CN111314053A/zh
Application granted granted Critical
Publication of CN111314053B publication Critical patent/CN111314053B/zh
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/06Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
    • H04L9/0643Hash functions, e.g. MD5, SHA, HMAC or f9 MAC
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3236Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions
    • H04L9/3239Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions involving non-keyed hash functions, e.g. modification detection codes [MDCs], MD5, SHA or RIPEMD
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3263Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving certificates, e.g. public key certificate [PKC] or attribute certificate [AC]; Public key infrastructure [PKI] arrangements
    • H04L9/3268Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving certificates, e.g. public key certificate [PKC] or attribute certificate [AC]; Public key infrastructure [PKI] arrangements using certificate validation, registration, distribution or revocation, e.g. certificate revocation list [CRL]

Abstract

本发明提供一种数据加密和解密方法,数据加密步骤如下:步骤1:根据用户设定的密钥,获取密钥的hash序列,并计算hash序列对应的位移权重值;步骤2:按照位移权重值对明文进行移位加密,得到移位密文,对移位密文进行Base64加密,使得密文为ASCII码序列,得到Base64密文;步骤3:根据hash序列生成混淆序列,使得混淆序列为ASCII码序列,并将混淆序列插入Base64密文中,得到正式密文;解决了在数字证书和区块链的验证过程中,加密数据容易被盗取,危险性较高的问题。

Description

一种数据加密和解密方法
技术领域
本发明涉及数据加密和解密领域,尤其涉及一种数据加密和解密方法。
背景技术
在数字证书和区块链的验证过程中,采用一对互相匹配的密钥对保密文件进行加密和解密操作,以保证文件的安全。目前,常用的加密和解密方法多是基于DES,3DES,RC5,IDEA、SM1等对称算法实现。
其中,DES算法为密码体制中的对称密码体制,又被称为美国数据加密标准,明文按64位进行分组,密钥长64位,密钥事实上是56位参与DES运算(第8、16、24、32、40、48、56、64位是校验位,使得每个密钥都有奇数个1)分组后的明文和56位的密钥按位替代或交换的方法形成密文的加密方法;3DES(或称为Triple DES)是三重数据加密算法(TDEA,TripleData Encryption Algorithm)块密码的通称,是对每个数据块应用三次DES加密算法,由于计算机运算能力的增强,原版DES密码的密钥长度变得容易被暴力破解,3DES即是设计用来提供一种相对简单的方法,即通过增加DES的密钥长度来避免类似的攻击,而不是设计一种全新的块密码算法;RC5分组密码算法是参数可变的分组密码算法,三个可变的参数是:分组大小、密钥大小和加密轮数,在此算法中使用了三种运算:异或、加和循环;IDEA算法是在DES算法的基础上发展出来的,类似于三重DES,和DES一样IDEA也是属于对称密钥算法,发展IDEA是因为DES具有密钥太短等缺点,已经过时,IDEA的密钥为128位,这么长的密钥在今后若干年内应该是安全的;SM1为对称加密,其加密强度与AES相当,该算法不公开,调用该算法时,需要通过加密芯片的接口进行调用。
以上所有提到的加密算法在相同的明文用同一个密钥进行加密得到的密文是不变的,这就给破译者一个比对密文的变化,再去尝试破解的可能性,在无需超高速计算的环境下就有可能被破解,导致采用以上算法实现的数据加密危险性较高;
发明内容
鉴于以上所述现有技术的缺点,本发明的目的在于提供一种数据加密和解密方法,用于解决在数字证书和区块链的验证过程中,加密数据容易被盗取,危险性较高的问题。
本发明提供一种数据加密和解密方法,所述方法包括以下步骤:
数据加密过程包括以下步骤:
步骤1:根据用户设定的密钥,获取密钥的hash序列,并计算hash序列对应的位移权重值;
步骤2:按照位移权重值对明文进行移位加密,得到移位密文,对移位密文进行Base64加密,使得密文为ASCII码序列,得到Base64密文;
步骤3:根据hash序列生成混淆序列,使得混淆序列为ASCII码序列,并将混淆序列插入Base64密文中,得到正式密文;
数据解密过程包括以下步骤:
步骤a:根据用户设定的密钥,获取hash序列,并根据hash序列计算混淆序列;
步骤b:根据混淆序列对密文进行混淆解码,得到Base64密文,对Base64密文进行Base64解密,得到移位密文;
步骤c:计算hash序列生成位移权重值,根据位移权重对移位密文进行移位解密,得到正式明文。
进一步的,密钥的hash序列是基于用户设定的密钥,通过hash32位算法获得的,且密钥和hash序列是一一对应的。
进一步的,移位加密和解密时,位移权重值为正数进行左位移,反之进行右位移。
如上所述,本发明的一种数据加密和解密方法,具有以下有益效果:
1、本发明中,使用同一个密钥对同样的明文进行加密,使得每次得到的正式密文都是不一样,且长度也是有所不同,极大的增大了密文比对破解的难度。
2、本发明中,采用双向移位加密算法,使得破解难度更高。
3、本发明中,适用于数字证书和区块链的验证,配合MD5码的密钥比对方案,可以实现对密文的有效验证,只要重新加密过所得的密文必然不同,对应的MD5码也不相同。
4、本发明中,对于127字符长的字符串,在i7-6500U 2.50GHz的CPU,8GB内存的硬件环境下,加密速度为每秒1万次。
附图说明
图1显示为本发明实施例中公开的数据加密方法操作流程图;
图2显示为本发明实施例中公开的数据解密方法操作流程图;
图3显示为本发明实施例中公开的数据加密算法步骤图;
图4显示为本发明实施例中公开的数据解密算法步骤图。
具体实施方式
以下通过特定的具体实例说明本发明的实施方式,本领域技术人员可由本说明书所揭露的内容轻易地了解本发明的其他优点与功效。本发明还可以通过另外不同的具体实施方式加以实施或应用,本说明书中的各项细节也可以基于不同观点与应用,在没有背离本发明的精神下进行各种修饰或改变。需说明的是,在不冲突的情况下,以下实施例及实施例中的特征可以相互组合。
需要说明的是,以下实施例中所提供的图示仅以示意方式说明本发明的基本构想,遂图式中仅显示与本发明中有关的组件而非按照实际实施时的组件数目、形状及尺寸绘制,其实际实施时各组件的型态、数量及比例可为一种随意的改变,且其组件布局型态也可能更为复杂。
本发明提供一种数据加密和解密方法,所述方法包括以下步骤:
如图1和3所示,数据加密过程包括以下步骤:
步骤1:根据用户设定的密钥,使用streamingXXHash32获取密钥的hash序列,并使用shiftWeight函数计算hash序列对应的位移权重值;
步骤2:使用compress_WT函数按照位移权重值对明文进行移位加密,得到移位密文;使用getEncoderBytes函数对移位密文进行Base64加密,使得密文为ASCII码序列,得到Base64密文;
步骤3:使用getUniformConfuseStringList函数根据hash序列生成混淆序列,使得混淆序列为ASCII码序列,并使用getCipherString函数将混淆序列插入Base64密文中,得到正式密文;
如图2和4所示,数据解密过程包括以下步骤:
步骤a:根据用户设定的密钥,使用streamingXXHash32函数获取hash序列,并使用getUniformConfuseScale函数计算hash序列计算混淆序列;
步骤b:使用getPlainString函数根据混淆序列对密文进行混淆解码,得到Base64密文,使用getDecoderBytes函数对Base64密文进行Base64解密,得到移位密文;
步骤c:使用shiftWeight函数计算hash序列生成位移权重值,使用uncompress_WT函数根据位移权重对移位密文进行移位解密,得到正式明文。
其中,密钥和hash序列是一一对应的,位移加密和解密时,位移权重值为正数进行左位移,反之进行右位移。
涉及函数包括:
1.hash序列生成函数
streamingXXHash32(String key)
String key是用户设定的密钥
返回long型的hash序列,有正负数;
2.位移权重值生成函数
shiftWeight(long hash_value)
hash_value是hash序列
返回int型权重值,有正负数;
3.移位加密函数
compress_WT(byte[]ogbyte,int weight)
ogbyte是明文的字节码,weight是位移权重值;
4.混淆序列函数
getUniformConfuseStringList(int weight)
weight是位移权重数
返回混淆序列;
5.Base64加密函数
getEncoderBytes(byte[]b)
b是需要加密的移位密文
返回base64密文字节码;
6.均匀混淆加密函数
getCipherString(byte[]plaintext,String[]uniform_confuse)plaintext是base64密文字节码
uniform_confuse是混淆序列
返回正式密文;
7.Base64解密函数
getDecoderBytes(byte[]b)
b是需要解密的base64密文
返回移位密文字节码;
8.均匀混淆解密函数
getPlainString(byte[]chipertext,int uniform_scale)
uniform_scale是混淆序列
返回移除混淆序列的base64密文;
9.移位解密函数
uncompress_WT(byte[]cpbyte,int weight)
cpbyte是移位密文的字节码,weight是位移权重值
返回明文;
综上所述,本发明用于解决在数字证书和区块链的验证过程中,加密数据容易被盗取,危险性较高的问题。所以,本发明有效克服了现有技术中的种种缺点而具高度产业利用价值。
上述实施例仅例示性说明本发明的原理及其功效,而非用于限制本发明。任何熟悉此技术的人士皆可在不违背本发明的精神及范畴下,对上述实施例进行修饰或改变。因此,举凡所属技术领域中具有通常知识者在未脱离本发明所揭示的精神与技术思想下所完成的一切等效修饰或改变,仍应由本发明的权利要求所涵盖。

Claims (3)

1.一种数据加密和解密方法,其特征在于,所述方法包括以下步骤:数据加密过程包括以下步骤:
步骤1:根据用户设定的密钥,获取密钥的hash序列,并计算hash序列对应的位移权重值;
步骤2:按照位移权重值对明文进行移位加密,得到移位密文,对移位密文进行Base64加密,使得密文为ASCII码序列,得到Base64密文;
步骤3:根据hash序列生成混淆序列,使得混淆序列为ASCII码序列,并将混淆序列插入Base64密文中,得到正式密文;
数据解密过程包括以下步骤:
步骤a:根据用户设定的密钥,获取hash序列,并根据hash序列计算混淆序列;
步骤b:根据混淆序列对密文进行混淆解码,得到Base64密文,对Base64密文进行Base64解密,得到移位密文;
步骤c:计算hash序列生成位移权重值,根据位移权重对移位密文进行移位解密,得到正式明文。
2.根据权利要求1所述的数据加密和解密方法,其特征在于:密钥的hash序列是基于用户设定的密钥,通过hash32位算法获得的,且密钥和hash序列是一一对应的。
3.根据权利要求1所述的数据加密和解密方法,其特征在于:移位加密和解密时,位移权重值为正数进行左位移,反之进行右位移。
CN201811517780.1A 2018-12-12 2018-12-12 一种数据加密和解密方法 Active CN111314053B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811517780.1A CN111314053B (zh) 2018-12-12 2018-12-12 一种数据加密和解密方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811517780.1A CN111314053B (zh) 2018-12-12 2018-12-12 一种数据加密和解密方法

Publications (2)

Publication Number Publication Date
CN111314053A CN111314053A (zh) 2020-06-19
CN111314053B true CN111314053B (zh) 2023-02-10

Family

ID=71161322

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811517780.1A Active CN111314053B (zh) 2018-12-12 2018-12-12 一种数据加密和解密方法

Country Status (1)

Country Link
CN (1) CN111314053B (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111967032B (zh) * 2020-08-27 2023-08-25 长城计算机软件与系统有限公司 基于混淆处理的文件加密方法及解密方法

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101739695A (zh) * 2009-11-26 2010-06-16 西北工业大学 一种基于三维Arnold映射的图像分组加密方法
CN102663325A (zh) * 2012-03-12 2012-09-12 苏州阔地网络科技有限公司 一种软件绑定硬件的方法及系统
CN103580851A (zh) * 2013-11-13 2014-02-12 福建省视通光电网络有限公司 信息加密及解密方法
CN103648093A (zh) * 2013-12-17 2014-03-19 重庆重邮汇测通信技术有限公司 基站工程参数加密传送方法
CN105812146A (zh) * 2016-05-26 2016-07-27 王云鹏 一种基于md5的双向加密数据保护方法
CN107332657A (zh) * 2017-07-21 2017-11-07 广州智慧城市发展研究院 一种基于区块链数字签名的加密方法及系统
CN108388808A (zh) * 2018-03-05 2018-08-10 郑州轻工业学院 基于希尔加密与动态dna编码的图像加密方法
CN108964872A (zh) * 2018-07-23 2018-12-07 武汉大学 一种基于aes的加密方法及装置

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP6187462B2 (ja) * 2012-07-18 2017-08-30 日本電気株式会社 ユニバーサルハッシュ関数演算装置、方法およびプログラム
CN104298926B (zh) * 2013-07-19 2017-11-10 腾讯科技(深圳)有限公司 一种运行加密文件的方法和装置
WO2016088453A1 (ja) * 2014-12-04 2016-06-09 日本電気株式会社 暗号化装置、復号装置、暗号処理システム、暗号化方法、復号方法、暗号化プログラム、及び復号プログラム
US10887080B2 (en) * 2017-03-16 2021-01-05 King Fahd University Of Petroleum And Minerals Double-hashing operation mode for encryption

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101739695A (zh) * 2009-11-26 2010-06-16 西北工业大学 一种基于三维Arnold映射的图像分组加密方法
CN102663325A (zh) * 2012-03-12 2012-09-12 苏州阔地网络科技有限公司 一种软件绑定硬件的方法及系统
CN103580851A (zh) * 2013-11-13 2014-02-12 福建省视通光电网络有限公司 信息加密及解密方法
CN103648093A (zh) * 2013-12-17 2014-03-19 重庆重邮汇测通信技术有限公司 基站工程参数加密传送方法
CN105812146A (zh) * 2016-05-26 2016-07-27 王云鹏 一种基于md5的双向加密数据保护方法
CN107332657A (zh) * 2017-07-21 2017-11-07 广州智慧城市发展研究院 一种基于区块链数字签名的加密方法及系统
CN108388808A (zh) * 2018-03-05 2018-08-10 郑州轻工业学院 基于希尔加密与动态dna编码的图像加密方法
CN108964872A (zh) * 2018-07-23 2018-12-07 武汉大学 一种基于aes的加密方法及装置

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
一种有效的Python字节码保护方法;陈悟等;《电子技术》;20170625(第06期);全文 *
网络环境下地图的混沌加密实用算法;钟尚平等;《计算机辅助设计与图形学学报》;20040220(第02期);全文 *

Also Published As

Publication number Publication date
CN111314053A (zh) 2020-06-19

Similar Documents

Publication Publication Date Title
CN111756523B (zh) 数据传输方法及装置
KR101516574B1 (ko) 형태보존 암호화를 위한 가변길이 블록암호 장치 및 방법
CN102664740B (zh) 一种基于远程授权的招投标文件加解密方法
CN109861810A (zh) 一种基于混沌块加密算法的数据加密方法及解密方法
CN105743645A (zh) 基于puf的流秘钥生成装置、方法及数据加密、解密方法
CN104378198A (zh) 一种基于分组密码体制的语音加密方法
Reyad et al. Key-based enhancement of data encryption standard for text security
CN111404953A (zh) 一种消息加密方法、解密方法及相关装置、系统
JP2000511755A (ja) バイナリーコード情報を暗号化する方法
CN103501220B (zh) 加密方法和装置
CN111314270B (zh) 一种基于有效期均匀分布对称算法的数据加密和解密方法
CN112385175A (zh) 一种用于数据加密和完整性的设备
CN111314053B (zh) 一种数据加密和解密方法
CN111314052B (zh) 一种数据加密和解密方法
CN106921486A (zh) 数据加密的方法和装置
CN105763322A (zh) 一种可混淆的加密密钥隔离数字签名方法及系统
JP5586758B1 (ja) 動的暗号化鍵生成システム
JP6631989B2 (ja) 暗号化装置、制御方法、及びプログラム
KR20180046425A (ko) 공개키 기반 암호화 방법 및 키 생성 서버
CN103475466A (zh) 一种USBKey总线保护实现方法
Charru et al. Improved Cryptography Algorithm to Enhanced Data Security
CN103746793A (zh) 一种数形文载加密和解密方法
CN102968598A (zh) 数字文件的解密方法
KR101553148B1 (ko) 비트 확장 방식을 이용한 암호화 장치 및 방법
JP5023610B2 (ja) データ授受方法及びシステム

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant