Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

补充一些金额转换方法以及强制创建文件方法(当目录不存在的时候先创建目录) #134

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions vjkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<junit.version>4.12</junit.version>
<assertj.version>2.6.0</assertj.version>
<mockito.version>2.18.3</mockito.version>
<bouncycastle.version>1.56</bouncycastle.version>
<bouncycastle.ext.version>1.56</bouncycastle.ext.version>

<!-- Plugin的属性 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -64,6 +66,26 @@
<optional>true</optional>
</dependency>

<!-- optional for bouncycastle -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk15on</artifactId>
<version>${bouncycastle.ext.version}</version>
<optional>true</optional>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class UncheckedException extends RuntimeException {
public UncheckedException(Throwable wrapped) {
super(wrapped);
}
public UncheckedException(String message) {
super(message);
}

@Override
public String getMessage() {
Expand Down
163 changes: 163 additions & 0 deletions vjkit/src/main/java/com/vip/vjtools/vjkit/enums/CipherAlgorithms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package com.vip.vjtools.vjkit.enums;

/**
* 加密算法枚举
* @author haven.zhang on 2018/10/23.
*/
public enum CipherAlgorithms {
RC2("RC2"),
RC4("RC4"),

DES_ECB_ZeroBytePadding("DES/ECB/ZeroBytePadding"),
DES_ECB_ISO10126Padding("DES/ECB/ISO10126Padding"),
DES_ECB_PKCS5Padding("DES/ECB/PKCS5Padding"),
DES_ECB_PKCS7Padding("DES/ECB/PKCS7Padding"),
DES_ECB_NoPadding("DES/ECB/NoPadding"),

DES_CBC_PKCS5Padding("DES/CBC/PKCS5Padding"),
DES_CBC_NoPadding("DES/CBC/NoPadding"),
DES_CBC_ZeroBytePadding("DES/CBC/ZeroBytePadding"),
DES_CBC_PKCS7Padding("DES/CBC/PKCS7Padding"),
DES_CBC_ISO10126Padding("DES/CBC/ISO10126Padding"),

DES_PCBC_PKCS5Padding("DES/PCBC/PKCS5Padding"),
DES_PCBC_NoPadding("DES/PCBC/NoPadding"),
DES_PCBC_ZeroBytePadding("DES/PCBC/ZeroBytePadding"),
DES_PCBC_PKCS7Padding("DES/PCBC/PKCS7Padding"),
DES_PCBC_ISO10126Padding("DES/PCBC/ISO10126Padding"),

DES_CFB_PKCS5Padding("DES/CFB/PKCS5Padding"),
DES_CFB_NoPadding("DES/CFB/NoPadding"),
DES_CFB_ZeroBytePadding("DES/CFB/ZeroBytePadding"),
DES_CFB_PKCS7Padding("DES/CFB/PKCS7Padding"),
DES_CFB_ISO10126Padding("DES/CFB/ISO10126Padding"),

DES_OFB_PKCS5Padding("DES/OFB/PKCS5Padding"),
DES_OFB_NoPadding("DES/OFB/NoPadding"),
DES_OFB_ZeroBytePadding("DES/OFB/ZeroBytePadding"),
DES_OFB_PKCS7Padding("DES/OFB/PKCS7Padding"),
DES_OFB_ISO10126Padding("DES/OFB/ISO10126Padding"),

DES_CTR_PKCS5Padding("DES/CTR/PKCS5Padding"),
DES_CTR_NoPadding("DES/CTR/NoPadding"),
DES_CTR_ZeroBytePadding("DES/CTR/ZeroBytePadding"),
DES_CTR_PKCS7Padding("DES/CTR/PKCS7Padding"),
DES_CTR_ISO10126Padding("DES/CTR/ISO10126Padding"),



Desede_ECB_ZeroBytePadding("Desede/ECB/ZeroBytePadding"),
Desede_ECB_ISO10126Padding("Desede/ECB/ISO10126Padding"),
Desede_ECB_PKCS7Padding("Desede/ECB/PKCS7Padding"),
Desede_ECB_PKCS5Padding("Desede/ECB/PKCS5Padding"),
Desede_ECB_NoPadding("Desede/ECB/NoPadding"),

Desede_CBC_PKCS5Padding("Desede/CBC/PKCS5Padding"),
Desede_CBC_PKCS7Padding("Desede/CBC/PKCS7Padding"),
Desede_CBC_ZeroBytePadding("Desede/CBC/ZeroBytePadding"),
Desede_CBC_ISO10126Padding("Desede/CBC/ISO10126Padding"),
Desede_CBC_NoPadding("Desede/CBC/NoPadding"),

Desede_PCBC_PKCS5Padding("Desede/PCBC/PKCS5Padding"),
Desede_PCBC_NoPadding("Desede/PCBC/NoPadding"),
Desede_PCBC_ZeroBytePadding("Desede/PCBC/ZeroBytePadding"),
Desede_PCBC_PKCS7Padding("Desede/PCBC/PKCS7Padding"),
Desede_PCBC_ISO10126Padding("Desede/PCBC/ISO10126Padding"),

Desede_CFB_PKCS5Padding("Desede/CFB/PKCS5Padding"),
Desede_CFB_NoPadding("Desede/CFB/NoPadding"),
Desede_CFB_ZeroBytePadding("Desede/CFB/ZeroBytePadding"),
Desede_CFB_PKCS7Padding("Desede/CFB/PKCS7Padding"),
Desede_CFB_ISO10126Padding("Desede/CFB/ISO10126Padding"),

Desede_OFB_PKCS5Padding("Desede/OFB/PKCS5Padding"),
Desede_OFB_NoPadding("Desede/OFB/NoPadding"),
Desede_OFB_ZeroBytePadding("DES/OFB/ZeroBytePadding"),
Desede_OFB_PKCS7Padding("Desede/OFB/PKCS7Padding"),
Desede_OFB_ISO10126Padding("Desede/OFB/ISO10126Padding"),

Desede_CTR_PKCS5Padding("Desede/CTR/PKCS5Padding"),
Desede_CTR_NoPadding("Desede/CTR/NoPadding"),
Desede_CTR_ZeroBytePadding("Desede/CTR/ZeroBytePadding"),
Desede_CTR_PKCS7Padding("Desede/CTR/PKCS7Padding"),
Desede_CTR_ISO10126Padding("Desede/CTR/ISO10126Padding"),

AES_ECB_ZeroBytePadding("AES/ECB/ZeroBytePadding"),
AES_ECB_ISO10126Padding("AES/ECB/ISO10126Padding"),
AES_ECB_PKCS7Padding("AES/ECB/PKCS7Padding"),
AES_ECB_PKCS5Padding("AES/ECB/PKCS5Padding"),
AES_ECB_NoPadding("AES/ECB/NoPadding"),

AES_CBC_PKCS5Padding("AES/CBC/PKCS5Padding"),
AES_CBC_PKCS7Padding("AES/CBC/PKCS7Padding"),
AES_CBC_ZeroBytePadding("AES/CBC/ZeroBytePadding"),
AES_CBC_ISO10126Padding("AES/CBC/ISO10126Padding"),
AES_CBC_NoPadding("AES/CBC/NoPadding"),

AES_PCBC_PKCS5Padding("AES/PCBC/PKCS5Padding"),
AES_PCBC_NoPadding("AES/PCBC/NoPadding"),
AES_PCBC_ZeroBytePadding("AES/PCBC/ZeroBytePadding"),
AES_PCBC_PKCS7Padding("AES/PCBC/PKCS7Padding"),
AES_PCBC_ISO10126Padding("AES/PCBC/ISO10126Padding"),

AES_CFB_PKCS5Padding("AES/CFB/PKCS5Padding"),
AES_CFB_NoPadding("AES/CFB/NoPadding"),
AES_CFB_ZeroBytePadding("AES/CFB/ZeroBytePadding"),
AES_CFB_PKCS7Padding("AES/CFB/PKCS7Padding"),
AES_CFB_ISO10126Padding("AES/CFB/ISO10126Padding"),

AES_OFB_PKCS5Padding("AES/OFB/PKCS5Padding"),
AES_OFB_NoPadding("AES/OFB/NoPadding"),
AES_OFB_ZeroBytePadding("DES/OFB/ZeroBytePadding"),
AES_OFB_PKCS7Padding("AES/OFB/PKCS7Padding"),
AES_OFB_ISO10126Padding("AES/OFB/ISO10126Padding"),

AES_CTR_PKCS5Padding("AES/CTR/PKCS5Padding"),
AES_CTR_NoPadding("AES/CTR/NoPadding"),
AES_CTR_ZeroBytePadding("AES/CTR/ZeroBytePadding"),
AES_CTR_PKCS7Padding("AES/CTR/PKCS7Padding"),
AES_CTR_ISO10126Padding("AES/CTR/ISO10126Padding"),


RSA_ECB_PKCS1Padding("RSA/ECB/PKCS1Padding"),
RSA_ECB_OAEPWithSHA1("RSA/ECB/OAEPWithSHA-1AndMGF1Padding"),
RSA_ECB_OAEPWithSHA256("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"),
RSA_ECB_NoPadding("RSA/ECB/NoPadding"),

PBEWithSHAAndDES("PBEWithSHAAndDES"),
PBEWithHmacSHA256AndAES_128("PBEWithHmacSHA256AndAES_128"),
PBEWithMD5AndTripeDES("PBEWithMD5AndTripeDES"),
PBEWithSHA1AndDESede("PBEWithSHA1AndDESede"),
PBEWithSHA1AndIDEA_CBC("PBEWithSHA1AndIDEA-CBC"),
PBEWITHSHAANDRC2("PBEWITHSHAANDRC2"),
PBEWITHSHAANDRC4("PBEWITHSHAANDRC4"),
PBEWITHMD2ANDDES("PBEWITHMD2ANDDES"),

PBEWithSHAAndTwofish_CBC("PBEWithSHAAndTwofish-CBC"),
PBEWithSHAAnd40BitRC4("PBEWithSHAAnd40BitRC4"),
PBEWithSHAAnd128BitRC4("PBEWithSHAAnd128BitRC4"),
PBEWithSHAAnd40BitRC2_CBC("PBEWithSHAAnd40BitRC2-CBC"),
PBEWithSHAAnd128BitRC2_CBC("PBEWithSHAAnd128BitRC2-CBC"),
PBEWithSHAAnd3_KeyTripleDES_CBC ("PBEWithSHAAnd3-KeyTripleDES-CBC"),
PBEWithSHAAnd2_KeyTripleDES_CBC("PBEWithSHAAnd2-KeyTripleDES-CBC"),
PBEWithSHA1AndRC2("PBEWithSHA1AndRC2"),
PBEWithMD5AndDES("PBEWithMD5AndDES"),
PBEWithSHA1AndDES("PBEWithSHA1AndDES"),
PBEWITHSHA256AND256BITAES_CBC_BC("PBEWITHSHA256AND256BITAES-CBC-BC"),
PBEWITHSHA256AND192BITAES_CBC_BC("PBEWITHSHA256AND192BITAES-CBC-BC"),
PBEWITHSHA256AND128BITAES_CBC_BC("PBEWITHSHA256AND128BITAES-CBC-BC"),
PBEWITHSHAAND256BITAES_CBC_BC("PBEWITHSHAAND256BITAES-CBC-BC"),
PBEWITHSHAAND192BITAES_CBC_BC("PBEWITHSHAAND192BITAES-CBC-BC"),
PBEWITHSHAAND128BITAES_CBC_BC("PBEWITHSHAAND128BITAES-CBC-BC"),
PBEWithMD5AndRC2("PBEWithMD5AndRC2");

private String value;

private CipherAlgorithms(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
46 changes: 46 additions & 0 deletions vjkit/src/main/java/com/vip/vjtools/vjkit/enums/EncryptedMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.vip.vjtools.vjkit.enums;

/**
* 加密模式
* @author haven.zhang
*/
public enum EncryptedMode {

/**
* 电码本模式(Electronic Codebook Book (ECB) 每一块都使用相同的秘钥进行加密
*/
ECB,
/**
* 密码分组链接模式(Cipher Block Chaining (CBC)) 在第一个块中需要使用初始化向量IV
* 每个明文块先与前一个密文块进行异或后,再进行加密
*/
CBC,
/**
* 填充密码块链接(PCBC,Propagating cipher-block chaining)或称为明文密码块链接(Plaintext cipher-block chaining)
*/
PCBC,
/**
* 计算器模式(Counter (CTR))
*/
CTR,

/**
* 密码反馈模式(Cipher FeedBack (CFB))
* CFB的加密工作分为两部分:
* 1.将一前段加密得到的密文再加密;
* 2.将第1步加密得到的数据与当前段的明文异或。
*/
CFB,
/**
* 和 CFB 一样,但是使用 8 位模式(不推荐)
*/
CFB8,
/**
* 输出反馈模式(Output FeedBack (OFB))
*/
OFB,
/**
* 和 OFB 一样,但是使用 8 位模式(不推荐)
*/
OFB8;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.vip.vjtools.vjkit.enums;

/**
* HmacSHA1摘要算法
* @author haven.zhang on 2018/10/26.
*/
public enum HmacAlgorithmType {
/**
* HmacSHA1摘要算法
*/
HMAC_SHA1("HmacSHA1"),
HMAC_SHA224("HmacSHA224"),
HMAC_SHA256("HmacSHA256"),
HMAC_SHA384("HmacSHA384"),
HMAC_SHA512("HmacSHA512"),
HMAC_MD2("HmacMD2"),
HMAC_MD4("HmacMD4"),
HMAC_MD5("HmacMD5");

public final String value;

HmacAlgorithmType(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.vip.vjtools.vjkit.enums;

/**
* The algorithm names in this section can be specified when generating an instance of KeyFactory.
* see https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
* @author haven.zhang on 2018/10/22.
*/
public enum KeyFactoryAlgorithms {
DiffieHellman,
DSA,
RSA,
EC;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.vip.vjtools.vjkit.enums;

/**
* 对称加密密码类型
* see https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyGenerator
* @author haven.zhang on 2018/10/22.
*/
public enum KeyGeneratorType {
RC2,
RC4,
HmacSHA1,
HmacSHA256,
HmacSHA384,
HmacSHA512,
HmacMD5,
Blowfish,
// ARCFOUR,
AES,
DES,
DESede;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.vip.vjtools.vjkit.enums;

/**
* The algorithm names in this section can be specified when generating an instance of KeyPairGenerator.
* @author haven.zhang on 2018/10/22.
*/
public enum KeyPairAlgorithms {
DiffieHellman,
DSA,//DSA密钥长度均为512~65536(64的整数倍),默认长度为1024
RSA,//RSA密钥长度均为512~65536(64的整数倍),默认长度为1024
EC;//EC秘钥长度为112-571,ECDSA:椭圆曲线数字签名算法 默认长度:256 特点:速度快,强度高,签名短。
}
40 changes: 40 additions & 0 deletions vjkit/src/main/java/com/vip/vjtools/vjkit/enums/KeyStoreType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.vip.vjtools.vjkit.enums;

/**
* keystore密钥库类型
* see https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyStore
* @author haven.zhang
*/
public enum KeyStoreType {
/**
* The proprietary keystore implementation provided by the SUN provider.
*/
JKS("JKS"),
/**
* The proprietary keystore implementation provided by the SunJCE provider.
*/
JCEKS("JCEKS"),
/**
* Bouncycastle 支持的密钥库类型
*/
BKS("BKS"),
/**
*Bouncycastle 支持的密钥库类型
*/
UBER("UBER"),
/**
* The transfer syntax for personal identity information as defined in PKCS #12.
*/
PKCS12("PKCS12");


private final String value;

private KeyStoreType(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
Loading