首页 > 编程知识 正文

破解rsa(开源社区 github)

时间:2023-05-04 18:24:45 阅读:74955 作者:1066

加密工具

对象(如字符串、byte[]和文件)的加密和解密工具的集合,其中包含多种加密方法。

加密类型

摘要

相关方法

简单加密

更改编码格式

Base64Util

单向加密

只能加密,不能解密

MD5Util、SHAUtil

对称加密

使用相同的私钥进行加密和解密

AESUtil、DESUtil

不对称加密

分为公开密钥和秘密密钥,加密一方,解密另一方

RSAUtil

使用方法

Base64util

方法

摘要

string base64编码程序(stringstr ) )。

编码

基于字符串的64解码的str (字符串str )。

解码

单元测试:

system.out.println(base64 );

//base64字符串加密解密测试

资产质量(r2n zu2xvb 3d kuk 3m loc=(n ),base64util.base64encodestr ) (GCSsloop中文) );

assertequals(GCSsloop中文),base64util.base64decodedstr ) (r2nzu2xvb3dkuk3mloc=n ) );

MD5Util

方法

摘要

字符串MD5(字符串)。

字符串加密

字符串MD5 (字符串字符串,字符串slat )。

加密字符串同时加盐

字符串MD5 (字符串,int times )。

多次加密

字符串MD5(文件文件)。

计算文件的md5数值

单元测试:

system.out.println(MD5 );

//MD5字符串加密测试

assertEquals (,MD5Util.md5 )、MD5 );

资产质量(386 D3 ff 3f a6 de f1 EC 307428 e 885 e 03 a1)、mD5util.MD5 ) GCSsloop中文);

资产质量(fd01 aa 74 bb 73 bbdb 094 BAE 28 a558 c6d1)、m D5 util.MD5 (GCS sloop中文)、(salt ) );

//MD5多次加密测试

资产质量(GCSsloop中文)、MD5util.MD5 )、GCSsloop中文)、0 );

资产质量(386 D3 ff 3f a6 de f1 EC 307428 e 885 e 03 a1)、mD5util.MD5 ) GCSsloop中文(,1 );

assert equals (2d9FDD 834 C5 c 852 fa 2f 946 b 670 f 3731 f )、m D5 util.MD5 (GCS sloop中文)、2 );

资产质量(211 DD 7a 16 D5 a 01 df 756278 ce a9 a 38d 53 )、MD5util.MD5 ) GCSsloop中文)、3 );

//md5文件MD5测试

file file=new file './encrypt/test/demo '

'.flv ';

资产质量(a4e 592 e 6160 e 0102 e 7e cc4 ab 6117 b 700 )、mD5util.MD5 )文件);

SHAUtil

方法

摘要

字符串sha (字符串,字符串类型)。

加密

单元测试:

system.out.println(sha );

//des字符串加密解密测试

String source='GcsSloop中文';

assert equals (b9dd 1d 754 ee3AC 16 DC 584 b8FD 4655 ca 581 a 0637 eab8ff 25128 b 0a 522372 e 7233 ),

shautil.sha(source,null );

assert equals (34d 44835 ce 4c 4d 7e cf 66428 e 49273 BF 02f 748 d 7213 be24 c 767 C5 f4f ),

shaUtil.sha(source,SHAUtil.SHA224 );

assert equals (b9dd 1d 754 ee3AC 16 DC 584 b8FD 4655 ca 581 a 0637 eab8ff 25128 b 0a 522372 e 7233 ),

>SHAUtil.sha(source, SHAUtil.SHA256));

assertEquals("2e3c27201c21b06b01289ebef09c9c36e752ca6a5b6425ca7b2501b4baaed29876954ca710b7e75c80b7b542df28fde6",

SHAUtil.sha(source, SHAUtil.SHA384));

assertEquals("bc3f55fcb03272ee166d7804ccba348ffba05ddce08bf3fab719fa2c97c8dc71993fc9524e21b8fee9491aafc0b309ebca797163bca45ece7c3dd73dae3698ee",

SHAUtil.sha(source, SHAUtil.SHA512));

AESUtil

方法

摘要

String aes(String content, String password, int type)

加密/解密

单元测试:

System.out.println("aes");

// aes 字符串加密解密测试

String source = "GcsSloop中文";

String key = "1234567890123456";

System.out.println("原数据 = " + source);

String aesStr = AESUtil.aes(source, key, Cipher.ENCRYPT_MODE);

System.out.println("加密后 = " + aesStr);

String result = AESUtil.aes(aesStr, key, Cipher.DECRYPT_MODE);

System.out.println("解密后 = " + result);

assertEquals(source, result);

DESUtil

方法

摘要

String des(String content, String password, int type)

加密/解密

单元测试:

System.out.println("des");

// des 字符串加密解密测试

String source = "GcsSloop中文";

String key = "1234567890123456";

System.out.println("原数据 = " + source);

String aesStr = DESUtil.des(source, key, Cipher.ENCRYPT_MODE);

System.out.println("加密后 = " + aesStr);

String result = DESUtil.des(aesStr, key, Cipher.DECRYPT_MODE);

System.out.println("解密后 = " + result);

assertEquals(source, result);

RSAUtil

方法

摘要

Map getKeyPair()

随机获取密钥(公钥和私钥), 客户端公钥加密,服务器私钥解密

String getKey(Map keyMap, boolean isPublicKey)

获取公钥/私钥(true:获取公钥,false:获取私钥)

String sign(byte[] data, String privateKey)

获取数字签名

boolean verify(byte[] data, String publicKey, String sign)

数字签名校验

byte[] rsa(byte[] data, String string, int type)

Rsa加密/解密(一般情况下,公钥加密私钥解密)

单元测试:

System.out.println("rsa");

// des 字符串加密解密测试

byte[] data = "GcsSloop中文".getBytes();

// 密钥与数字签名获取

Map keyMap = RSAUtil.getKeyPair();

String publicKey = RSAUtil.getKey(keyMap, true);

System.out.println("rsa获取公钥: " + publicKey);

String privateKey = RSAUtil.getKey(keyMap, false);

System.out.println("rsa获取私钥: " + privateKey);

// 公钥加密私钥解密

byte[] rsaPublic =

RSAUtil.rsa(data, publicKey, RSAUtil.RSA_PUBLIC_ENCRYPT);

System.out.println("rsa公钥加密: " + new String(rsaPublic));

System.out.println("rsa私钥解密: " + new String(

RSAUtil.rsa(rsaPublic, privateKey, RSAUtil.RSA_PRIVATE_DECRYPT)));

// 私钥加密公钥解密

byte[] rsaPrivate =

RSAUtil.rsa(data, privateKey, RSAUtil.RSA_PRIVATE_ENCRYPT);

System.out.println("rsa私钥加密: " + new String(rsaPrivate));

System.out.println("rsa公钥解密: " + new String(

RSAUtil.rsa(rsaPrivate, publicKey, RSAUtil.RSA_PUBLIC_DECRYPT)));

// 私钥签名及公钥签名校验

String signStr = RSAUtil.sign(rsaPrivate, privateKey);

System.out.println("rsa数字签名生成: " + signStr);

System.out.println("rsa数字签名校验: " + RSAUtil.verify(rsaPrivate, publicKey, signStr));

添加方法

在你的项目根 build.gradle 中添加上远程仓库:

allprojects {

repositories {

jcenter()

// 就是下面这一行

maven { url "http://lib.gcssloop.com/repository/gcssloop-central/" }

}

}

在需要引用的 module 添加具体依赖。

compile 'com.gcssloop.util:encrypt:1.0.0@aar'

版本信息

v1.0.0

添加基本的加密解密工具和辅助工具类。

base

Base64

BaseUtils

CloseUtils

CryptoProvider

TextUtils

encode

Base64Util

oneway

MD5Util

SHAUtil

symmetric

AESUtil

DESUtil

unsymmetric

RSAUtil

备注

本工具库中大部分代码参考自 一个聚合的加解密工具类 但在测试过程中发现部分方法结果不正确,以及部分方法在Android升级过程中进行了修改,所以改进了一部分,特此制作一个工具库,如果发现有什么不准确的地方欢迎提交 Issues。

参考资料

作者简介

版权信息

Copyright (c) 2017 GcsSloop

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。