
com.github.joekerouac.common.tools.crypto.constant.CipherSuite Maven / Gradle / Ivy
The newest version!
// Generated by delombok at Fri Mar 14 11:41:38 CST 2025
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
* file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
* to You 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.
*/
package com.github.joekerouac.common.tools.crypto.constant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* int类型的静态字段的字段名必须是加密套件名,值是对应的id
*
* 密码套件说明:TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,
*
其中TLS是固定的
* ECDH_RSA表示密钥交换使用ECDH算法, 使用RSA算法做签名
* AES_256_GCM表示使用AES算法,密钥256位,GCM是AES的加密模式
* SHA384表示MAC算法使用的hash算法
*
* @since 1.0.0
* @author JoeKerouac
*/
public class CipherSuite {
private static final int TLS_NULL_WITH_NULL_NULL = 0;
private static final int TLS_RSA_WITH_NULL_MD5 = 1;
private static final int TLS_RSA_WITH_NULL_SHA = 2;
private static final int TLS_RSA_EXPORT_WITH_RC4_40_MD5 = 3;
private static final int TLS_RSA_WITH_RC4_128_MD5 = 4;
private static final int TLS_RSA_WITH_RC4_128_SHA = 5;
private static final int TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 = 6;
private static final int TLS_RSA_WITH_IDEA_CBC_SHA = 7;
private static final int TLS_RSA_EXPORT_WITH_DES40_CBC_SHA = 8;
private static final int TLS_RSA_WITH_DES_CBC_SHA = 9;
private static final int TLS_RSA_WITH_3DES_EDE_CBC_SHA = 10;
private static final int TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA = 11;
private static final int TLS_DH_DSS_WITH_DES_CBC_SHA = 12;
private static final int TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA = 13;
private static final int TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA = 14;
private static final int TLS_DH_RSA_WITH_DES_CBC_SHA = 15;
private static final int TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA = 16;
private static final int TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA = 17;
private static final int TLS_DHE_DSS_WITH_DES_CBC_SHA = 18;
private static final int TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA = 19;
private static final int TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA = 20;
private static final int TLS_DHE_RSA_WITH_DES_CBC_SHA = 21;
private static final int TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA = 22;
private static final int TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 = 23;
private static final int TLS_DH_anon_WITH_RC4_128_MD5 = 24;
private static final int TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA = 25;
private static final int TLS_DH_anon_WITH_DES_CBC_SHA = 26;
private static final int TLS_DH_anon_WITH_3DES_EDE_CBC_SHA = 27;
/*
* RFC 3268
*/
public static final int TLS_RSA_WITH_AES_128_CBC_SHA = 47;
public static final int TLS_DH_DSS_WITH_AES_128_CBC_SHA = 48;
public static final int TLS_DH_RSA_WITH_AES_128_CBC_SHA = 49;
public static final int TLS_DHE_DSS_WITH_AES_128_CBC_SHA = 50;
public static final int TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 51;
public static final int TLS_DH_anon_WITH_AES_128_CBC_SHA = 52;
public static final int TLS_RSA_WITH_AES_256_CBC_SHA = 53;
public static final int TLS_DH_DSS_WITH_AES_256_CBC_SHA = 54;
public static final int TLS_DH_RSA_WITH_AES_256_CBC_SHA = 55;
public static final int TLS_DHE_DSS_WITH_AES_256_CBC_SHA = 56;
public static final int TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 57;
public static final int TLS_DH_anon_WITH_AES_256_CBC_SHA = 58;
/*
* RFC 4279
*/
public static final int TLS_PSK_WITH_RC4_128_SHA = 138;
public static final int TLS_PSK_WITH_3DES_EDE_CBC_SHA = 139;
public static final int TLS_PSK_WITH_AES_128_CBC_SHA = 140;
public static final int TLS_PSK_WITH_AES_256_CBC_SHA = 141;
public static final int TLS_DHE_PSK_WITH_RC4_128_SHA = 142;
public static final int TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA = 143;
public static final int TLS_DHE_PSK_WITH_AES_128_CBC_SHA = 144;
public static final int TLS_DHE_PSK_WITH_AES_256_CBC_SHA = 145;
public static final int TLS_RSA_PSK_WITH_RC4_128_SHA = 146;
public static final int TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA = 147;
public static final int TLS_RSA_PSK_WITH_AES_128_CBC_SHA = 148;
public static final int TLS_RSA_PSK_WITH_AES_256_CBC_SHA = 149;
/*
* RFC 4492
*/
public static final int TLS_ECDH_ECDSA_WITH_NULL_SHA = 49153;
public static final int TLS_ECDH_ECDSA_WITH_RC4_128_SHA = 49154;
public static final int TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = 49155;
public static final int TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = 49156;
public static final int TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = 49157;
public static final int TLS_ECDHE_ECDSA_WITH_NULL_SHA = 49158;
public static final int TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = 49159;
public static final int TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = 49160;
public static final int TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 49161;
public static final int TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 49162;
public static final int TLS_ECDH_RSA_WITH_NULL_SHA = 49163;
public static final int TLS_ECDH_RSA_WITH_RC4_128_SHA = 49164;
public static final int TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = 49165;
public static final int TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = 49166;
public static final int TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = 49167;
public static final int TLS_ECDHE_RSA_WITH_NULL_SHA = 49168;
public static final int TLS_ECDHE_RSA_WITH_RC4_128_SHA = 49169;
public static final int TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = 49170;
public static final int TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 49171;
public static final int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 49172;
public static final int TLS_ECDH_anon_WITH_NULL_SHA = 49173;
public static final int TLS_ECDH_anon_WITH_RC4_128_SHA = 49174;
public static final int TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA = 49175;
public static final int TLS_ECDH_anon_WITH_AES_128_CBC_SHA = 49176;
public static final int TLS_ECDH_anon_WITH_AES_256_CBC_SHA = 49177;
/*
* RFC 5054
*/
public static final int TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA = 49178;
public static final int TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA = 49179;
public static final int TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA = 49180;
public static final int TLS_SRP_SHA_WITH_AES_128_CBC_SHA = 49181;
public static final int TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA = 49182;
public static final int TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA = 49183;
public static final int TLS_SRP_SHA_WITH_AES_256_CBC_SHA = 49184;
public static final int TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA = 49185;
public static final int TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA = 49186;
/*
* RFC 5289
*/
private static final int TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 49187;
private static final int TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 49188;
private static final int TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 = 49189;
private static final int TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 = 49190;
private static final int TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 49191;
private static final int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 49192;
private static final int TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 = 49193;
private static final int TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 = 49194;
private static final int TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 49195;
private static final int TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 49196;
private static final int TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 = 49197;
private static final int TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 = 49198;
private static final int TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 49199;
private static final int TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 49200;
private static final int TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 = 49201;
private static final int TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 = 49202;
/*
* RFC 5746
*/
public static final int TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 255;
private static final Map ALL_SUPPORTS = new HashMap<>();
static {
// 百度不支持AES256的,只能用AES128的
ALL_SUPPORTS.put(TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, new CipherSuite("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, MacDesc.NULL_MAC, KeyExchange.ECDHE_RSA, CipherDesc.AES_128_GCM, HashDesc.SHA256, true));
ALL_SUPPORTS.put(TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, new CipherSuite("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, MacDesc.NULL_MAC, KeyExchange.ECDHE_RSA, CipherDesc.AES_256_GCM, HashDesc.SHA384, true));
}
/**
* 套件名
*/
private final String name;
/**
* 加密套件id
*/
private final int suite;
/**
* mac算法(对应的hash算法)
*/
private final MacDesc macDesc;
/**
* 密钥交换算法名
*/
private final KeyExchange keyExchange;
/**
* 加密算法名
*/
private final CipherDesc cipher;
private final HashDesc hashDesc;
/**
* 是否是包含ECC算法
*/
private final boolean ec;
public CipherSuite(String name, int suite, MacDesc macDesc, KeyExchange keyExchange, CipherDesc cipher, HashDesc hashDesc, boolean ec) {
this.name = name;
this.suite = suite;
this.macDesc = macDesc;
this.keyExchange = keyExchange;
this.cipher = cipher;
this.hashDesc = hashDesc;
this.ec = ec;
}
/**
* 根据加密套件的id获取加密套件
*
* @param id
* 加密套件id
* @return 加密套件
*/
public static CipherSuite getById(int id) {
return ALL_SUPPORTS.get(id);
}
/**
* 获取当前系统支持的所有加密套件
*
* @return 所有加密套件
*/
public static List getAllSupports() {
return new ArrayList<>(ALL_SUPPORTS.values());
}
@Override
public String toString() {
return name;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof CipherSuite)) return false;
final CipherSuite other = (CipherSuite) o;
if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getSuite() != other.getSuite()) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
protected boolean canEqual(final java.lang.Object other) {
return other instanceof CipherSuite;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.getSuite();
return result;
}
/**
* 套件名
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public String getName() {
return this.name;
}
/**
* 加密套件id
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int getSuite() {
return this.suite;
}
/**
* mac算法(对应的hash算法)
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public MacDesc getMacDesc() {
return this.macDesc;
}
/**
* 密钥交换算法名
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public KeyExchange getKeyExchange() {
return this.keyExchange;
}
/**
* 加密算法名
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public CipherDesc getCipher() {
return this.cipher;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public HashDesc getHashDesc() {
return this.hashDesc;
}
/**
* 是否是包含ECC算法
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public boolean isEc() {
return this.ec;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy