- 浏览: 2542839 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
bouncycastle(3)Learn from others DES
DES - Data Encryption Standard
The most important parameters are as follow: Key, Data, Mode.
A will create the key, publish the key to B, create the encryption data with key, publish the data to B
B will receive the key and the data, decrypt the data with key.
The most import class is as follow:
package com.sillycat.easycastle.encryption;
import java.security.Key;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
public abstract class DESCoder extends Coder {
/**
* ALGORITHM
* we can change the algorithm to every value as follow,
* the key size will change according to the algorithm you choose
* <pre>
* DES key size must be equal to 56
* DESede(TripleDES) key size must be equal to 112 or 168
* AES key size must be equal to 128, 192 or 256,but 192 and 256 bits may not be available
* Blowfish key size must be multiple of 8, and can only range from 32 to 448 (inclusive)
* RC2 key size must be between 40 and 1024 bits
* RC4(ARCFOUR) key size must be between 40 and 1024 bits
* </pre>
*/
public static final String ALGORITHM = "DES";
/**
* convert to key
* @param key
* @return
* @throws Exception
*/
private static Key toKey(byte[] key) throws Exception {
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
SecretKey secretKey = keyFactory.generateSecret(dks);
// If we want to use other algorithm as AES,Blowfish, Just use the follow statement
// SecretKey secretKey = new SecretKeySpec(key, ALGORITHM);
return secretKey;
}
/**
* decrypt the data
* @param data
* @param key
* @return
* @throws Exception
*/
public static byte[] decrypt(byte[] data, String key) throws Exception {
Key k = toKey(decryptBASE64(key));
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, k);
return cipher.doFinal(data);
}
/**
* encrypt
*
* @param data
* @param key
* @return
* @throws Exception
*/
public static byte[] encrypt(byte[] data, String key) throws Exception {
Key k = toKey(decryptBASE64(key));
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, k);
return cipher.doFinal(data);
}
/**
* generate the key
*
* @return
* @throws Exception
*/
public static String initKey() throws Exception {
return initKey(null);
}
/**
* generate the key
*
* @param seed
* @return
* @throws Exception
*/
public static String initKey(String seed) throws Exception {
SecureRandom secureRandom = null;
if (seed != null) {
secureRandom = new SecureRandom(decryptBASE64(seed));
} else {
secureRandom = new SecureRandom();
}
KeyGenerator kg = KeyGenerator.getInstance(ALGORITHM);
kg.init(secureRandom);
SecretKey secretKey = kg.generateKey();
return encryptBASE64(secretKey.getEncoded());
}
}
And the test class is as follow:
package com.sillycat.easycastle.encryption;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class DESCoderTest {
@Test
public void test() throws Exception {
String inputStr = "DES";
String key = DESCoder.initKey();
System.out.println("original:\t" + inputStr);
System.out.println("key:\t" + key);
byte[] inputData = inputStr.getBytes();
inputData = DESCoder.encrypt(inputData, key);
System.out.println("encryption data:\t" + inputData);
System.out.println("encryption data(base64+des):\t" + DESCoder.encryptBASE64(inputData));
byte[] outputData = DESCoder.decrypt(inputData, key);
String outputStr = new String(outputData);
System.out.println("decryption data:\t" + outputStr);
assertEquals(inputStr, outputStr);
}
}
This project is host by github and project name is easycastle.
references:
http://snowolf.iteye.com/blog/380034
DES - Data Encryption Standard
The most important parameters are as follow: Key, Data, Mode.
A will create the key, publish the key to B, create the encryption data with key, publish the data to B
B will receive the key and the data, decrypt the data with key.
The most import class is as follow:
package com.sillycat.easycastle.encryption;
import java.security.Key;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
public abstract class DESCoder extends Coder {
/**
* ALGORITHM
* we can change the algorithm to every value as follow,
* the key size will change according to the algorithm you choose
* <pre>
* DES key size must be equal to 56
* DESede(TripleDES) key size must be equal to 112 or 168
* AES key size must be equal to 128, 192 or 256,but 192 and 256 bits may not be available
* Blowfish key size must be multiple of 8, and can only range from 32 to 448 (inclusive)
* RC2 key size must be between 40 and 1024 bits
* RC4(ARCFOUR) key size must be between 40 and 1024 bits
* </pre>
*/
public static final String ALGORITHM = "DES";
/**
* convert to key
* @param key
* @return
* @throws Exception
*/
private static Key toKey(byte[] key) throws Exception {
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
SecretKey secretKey = keyFactory.generateSecret(dks);
// If we want to use other algorithm as AES,Blowfish, Just use the follow statement
// SecretKey secretKey = new SecretKeySpec(key, ALGORITHM);
return secretKey;
}
/**
* decrypt the data
* @param data
* @param key
* @return
* @throws Exception
*/
public static byte[] decrypt(byte[] data, String key) throws Exception {
Key k = toKey(decryptBASE64(key));
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, k);
return cipher.doFinal(data);
}
/**
* encrypt
*
* @param data
* @param key
* @return
* @throws Exception
*/
public static byte[] encrypt(byte[] data, String key) throws Exception {
Key k = toKey(decryptBASE64(key));
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, k);
return cipher.doFinal(data);
}
/**
* generate the key
*
* @return
* @throws Exception
*/
public static String initKey() throws Exception {
return initKey(null);
}
/**
* generate the key
*
* @param seed
* @return
* @throws Exception
*/
public static String initKey(String seed) throws Exception {
SecureRandom secureRandom = null;
if (seed != null) {
secureRandom = new SecureRandom(decryptBASE64(seed));
} else {
secureRandom = new SecureRandom();
}
KeyGenerator kg = KeyGenerator.getInstance(ALGORITHM);
kg.init(secureRandom);
SecretKey secretKey = kg.generateKey();
return encryptBASE64(secretKey.getEncoded());
}
}
And the test class is as follow:
package com.sillycat.easycastle.encryption;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class DESCoderTest {
@Test
public void test() throws Exception {
String inputStr = "DES";
String key = DESCoder.initKey();
System.out.println("original:\t" + inputStr);
System.out.println("key:\t" + key);
byte[] inputData = inputStr.getBytes();
inputData = DESCoder.encrypt(inputData, key);
System.out.println("encryption data:\t" + inputData);
System.out.println("encryption data(base64+des):\t" + DESCoder.encryptBASE64(inputData));
byte[] outputData = DESCoder.decrypt(inputData, key);
String outputStr = new String(outputData);
System.out.println("decryption data:\t" + outputStr);
assertEquals(inputStr, outputStr);
}
}
This project is host by github and project name is easycastle.
references:
http://snowolf.iteye.com/blog/380034
发表评论
-
Update Site will come soon
2021-06-02 04:10 1672I am still keep notes my tech n ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 424Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 428Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 367Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 445VPN Server 2020(2)Docker on Cen ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 348Nginx Deal with OPTIONS in HTTP ... -
PDF to HTML 2020(1)pdftohtml Linux tool or PDFBox
2020-01-29 07:37 400PDF to HTML 2020(1)pdftohtml Li ... -
Elasticsearch Cluster 2019(2)Kibana Issue or Upgrade
2020-01-12 03:25 713Elasticsearch Cluster 2019(2)Ki ... -
Spark Streaming 2020(1)Investigation
2020-01-08 07:19 291Spark Streaming 2020(1)Investig ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 289Hadoop Docker 2019 Version 3.2. ... -
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 236MongoDB 2019(3)Security and Aut ... -
MongoDB 2019(1)Install 4.2.1 Single and Cluster
2019-11-11 05:07 289MongoDB 2019(1) Follow this ht ... -
Monitor Tool 2019(1)Monit Installation and Usage
2019-10-17 08:22 321Monitor Tool 2019(1)Monit Insta ... -
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
2019-10-12 06:15 307Ansible 2019(1)Introduction and ... -
Timezone and Time on All Servers and Docker Containers
2019-10-10 11:18 329Timezone and Time on All Server ... -
Kafka Cluster 2019(6) 3 Nodes Cluster on CentOS7
2019-10-05 23:28 275Kafka Cluster 2019(6) 3 Nodes C ... -
K8S Helm(1)Understand YAML and Kubectl Pod and Deployment
2019-10-01 01:21 317K8S Helm(1)Understand YAML and ... -
Rancher and k8s 2019(5)Private Registry
2019-09-27 03:25 354Rancher and k8s 2019(5)Private ... -
Jenkins 2019 Cluster(1)Version 2.194
2019-09-12 02:53 439Jenkins 2019 Cluster(1)Version ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 367Redis Cluster 2019(3)Redis Clus ...
相关推荐
1. **bcprov-jdk15on-1.62.jar**:这是BouncyCastle的主要加密提供者包,提供了广泛的加密算法实现,如RSA、AES、DES、SHA等。它支持Java 1.5及更高版本,因此名称中的"jdk15on"表示这个版本适用于Java 1.5及以上。...
1. **对称加密**:AES(高级加密标准)、DES(数据加密标准)、3DES(三重DES)、Blowfish等。 2. **非对称加密**:RSA、DSA(数字签名算法)、ECC(椭圆曲线加密)等。 3. **哈希函数**:MD5、SHA-1、SHA-256、SHA-...
BouncyCastle.Crypto.dll是一个开源的加密库,由The Legion of the Bouncy Castle组织开发,提供了大量加密算法和协议的实现,包括但不限于RSA、AES、DES、DH(Diffie-Hellman)、ECC(椭圆曲线密码学)等。...
对称加密是使用同一密钥进行加密和解密的方法,如 DES(Data Encryption Standard)、3DES、AES(Advanced Encryption Standard)等。Bouncy Castle 提供了这些算法的实现,允许开发者在应用中方便地集成数据保护。...
这个库是BouncyCastle项目的一部分,它是一个开源的密码学API,支持多种加密算法和标准,如RSA、AES、DES、SHA、HMAC等。BouncyCastle库分为两个部分:轻量级加密API(Lightweight Cryptography API)和PKCS(Public...
3. **数字签名**:Bouncy Castle可以创建和验证数字签名,这在确保数据完整性和来源验证时非常有用。RSA、DSA和ECC都可以用于生成数字签名。 4. **哈希函数**:哈希函数将任意长度的输入转换为固定长度的输出,常...
2. **广泛的密码学算法**:BouncyCastle 支持众多加密算法,如AES、DES、3DES、Blowfish、RSA、DSA、ECDSA等,还包括哈希函数如SHA-1、SHA-256、MD5等,以及消息认证码(MAC)和伪随机数生成器(PRNG)。 3. **PKCS...
BouncyCastle.Crypto.dll是.NET版本的核心组件,包含了大量加密算法的实现,如对称加密(如AES、DES、3DES)、非对称加密(RSA、DSA、ECC)、哈希算法(MD5、SHA-1、SHA-256等)以及消息认证码(MAC)等。...
3. 密钥管理:对于密钥生成、存储和分发,BouncyCastle.Crypto.dll提供了完整的解决方案,包括硬件安全模块(HSM)的接口,确保密钥的安全管理。 五、总结 BouncyCastle.Crypto.dll 1.8.2版本是.NET开发者进行安全...
Bouncy Castle 支持多种加密算法,包括对称加密(如 AES、DES、3DES)、非对称加密(RSA、DSA、ECDSA)、哈希函数(MD5、SHA-1、SHA-256 及以上)、消息认证码(MAC)等。这些算法的实现使得开发人员能够灵活选择...
《BouncyCastle1.59帮助文档:深入理解与CHM制作详解》 BouncyCastle,作为Java和.NET平台上广泛使用的开源加密库,为开发者提供了丰富的加密算法、密码学标准接口以及证书处理功能。这份“BouncyCastle1.59帮助...
3. **bouncycastle.jar**:这个文件没有明确的版本号和平台标识,可能是通用或者特定版本的别名。通常,BouncyCastle的jar文件会包含一个版本号,所以这可能是某个特定构建的打包文件,或者是一个较早时期命名的习惯...
1. **加密算法支持**:`org.bouncycastle`提供了大量的对称和非对称加密算法,例如AES(高级加密标准)、Blowfish、DES(数据加密标准)、3DES(三重DES)、RSA(公钥加密标准)、DSA(数字签名算法)等。...
总结来说,"BouncyCastle,SM2、SM3、SM4 证书加解密应用例子"是一个关于使用C#和BouncyCastle库实现中国国密标准的实战案例,适用于需要跨平台、高安全性的应用程序。通过理解和应用这个示例,开发者可以增强在密码...
BouncyCastle是JAVA专属库,但出来了C#的库。这个非常实用。仅仅一个dll文件
3. 创建Signer:BouncyCastle中的`Org.BouncyCastle.Security.SignerUtilities`类提供了一个静态方法`GetSigner`,可以根据所选算法(如SHA256WithRSA)获取一个`ISigner`实例,这个实例负责实际的签名计算。...
在C#编程环境中,虽然.NET框架提供了内置的安全类如RSACryptoServiceProvider,但在某些场景下,如与Java平台交互或者需要更灵活的加密库时,可能会选择第三方库,例如BouncyCastle。BouncyCastle是一个强大的开源...