Class SM2PublicKeyEntryDecoder
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.config.keys.impl.AbstractIdentityResourceLoader<ECPublicKey,ECPrivateKey>
org.apache.sshd.common.config.keys.impl.AbstractKeyEntryResolver<ECPublicKey,ECPrivateKey>
org.apache.sshd.common.config.keys.impl.AbstractPublicKeyEntryDecoder<ECPublicKey,ECPrivateKey>
org.apache.sshd.common.config.keys.impl.SM2PublicKeyEntryDecoder
- All Implemented Interfaces:
IdentityResourceLoader<ECPublicKey,,ECPrivateKey> KeyEntryResolver<ECPublicKey,,ECPrivateKey> KeyTypeNamesSupport,PublicKeyEntryDecoder<ECPublicKey,,ECPrivateKey> PublicKeyEntryResolver,PublicKeyRawDataDecoder<ECPublicKey>
public class SM2PublicKeyEntryDecoder
extends AbstractPublicKeyEntryDecoder<ECPublicKey,ECPrivateKey>
SM2公钥解码器,支持64字节X+Y坐标的ASN.1编码格式
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SM2PublicKeyEntryDecoderstatic final intstatic final intstatic final intstatic final Stringstatic final StringFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.common.config.keys.IdentityResourceLoader
MAX_BIGINT_OCTETS_COUNTFields inherited from interface org.apache.sshd.common.config.keys.PublicKeyEntryResolver
FAILING, IGNORING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecodePublicKey(SessionContext session, String keyType, InputStream keyData, Map<String, String> headers) private ECPointdecodeRawSM2PublicKey(byte[] rawData) 解析64字节原始格式(前32字节X,后32字节Y)encodePublicKey(OutputStream s, ECPublicKey key) private byte[]将公钥点编码为ASN.1 SEQUENCE格式generateKeyPair(int keySize) private ECParameterSpecprivate BigIntegerparseASN1Integer(org.bouncycastle.asn1.ASN1Encodable obj) private ECPointparseSM2PublicKey(byte[] asn1Data) 解析64字节X+Y坐标的ASN.1编码格式Methods inherited from class org.apache.sshd.common.config.keys.impl.AbstractPublicKeyEntryDecoder
parseBooleanHeaderMethods inherited from class org.apache.sshd.common.config.keys.impl.AbstractKeyEntryResolver
generatePrivateKey, generatePublicKey, toStringMethods inherited from class org.apache.sshd.common.config.keys.impl.AbstractIdentityResourceLoader
getPrivateKeyType, getPublicKeyType, getSupportedKeyTypesMethods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sshd.common.config.keys.IdentityResourceLoader
getPrivateKeyType, getPublicKeyTypeMethods inherited from interface org.apache.sshd.common.config.keys.KeyEntryResolver
cloneKeyPairMethods inherited from interface org.apache.sshd.common.config.keys.KeyTypeNamesSupport
getSupportedKeyTypesMethods inherited from interface org.apache.sshd.common.config.keys.PublicKeyEntryDecoder
decodePublicKeyByType, resolveMethods inherited from interface org.apache.sshd.common.config.keys.PublicKeyRawDataDecoder
decodePublicKey, decodePublicKey
-
Field Details
-
SM2_KEY_TYPE
- See Also:
-
SM2_CURVE_NAME
- See Also:
-
PUBLIC_KEY_ASN1_MIN_LENGTH
public static final int PUBLIC_KEY_ASN1_MIN_LENGTH- See Also:
-
MAX_ALLOWED_POINT_SIZE
public static final int MAX_ALLOWED_POINT_SIZE- See Also:
-
MAX_CURVE_NAME_LENGTH
public static final int MAX_CURVE_NAME_LENGTH- See Also:
-
INSTANCE
-
-
Constructor Details
-
SM2PublicKeyEntryDecoder
public SM2PublicKeyEntryDecoder()
-
-
Method Details
-
decodePublicKey
public ECPublicKey decodePublicKey(SessionContext session, String keyType, InputStream keyData, Map<String, String> headers) throws IOException, GeneralSecurityException- Parameters:
session- TheSessionContextfor invoking this command - may benullif not invoked within a session context (e.g., offline tool or session unknown).keyType- The reported / encode key typekeyData- The key data bytes stream positioned after the key type decoding and making sure it is one of the supported typesheaders- Any headers that may have been available when data was read- Returns:
- The decoded
PublicKey - Throws:
IOException- If failed to read from the data streamGeneralSecurityException- If failed to generate the key
-
parseSM2PublicKey
解析64字节X+Y坐标的ASN.1编码格式- Throws:
IOException
-
parseASN1Integer
- Throws:
IOException
-
decodeRawSM2PublicKey
解析64字节原始格式(前32字节X,后32字节Y)- Throws:
IOException
-
clonePublicKey
- Parameters:
key- ThePublicKeyto clone - ignored ifnull- Returns:
- The cloned key (or
nullif no original key) - Throws:
GeneralSecurityException- If failed to clone the key
-
clonePrivateKey
- Parameters:
key- ThePrivateKeyto clone - ignored ifnull- Returns:
- The cloned key (or
nullif no original key) - Throws:
GeneralSecurityException- If failed to clone the key
-
encodePublicKey
Description copied from interface:PublicKeyEntryDecoder- Parameters:
s- TheOutputStreamto write the data tokey- ThePublicKey- may not benull- Returns:
- The key type value - one of the
KeyTypeNamesSupport.getSupportedKeyTypes() - Throws:
IOException- If failed to generate the encoding
-
encodeSM2PublicKey
将公钥点编码为ASN.1 SEQUENCE格式- Throws:
IOException
-
getKeyFactoryInstance
- Returns:
- A
KeyFactorysuitable for the specific decoder type - Throws:
GeneralSecurityException- If failed to create one
-
generateKeyPair
- Parameters:
keySize- Key size in bits- Returns:
- A
KeyPairwith the specified key size - Throws:
GeneralSecurityException- if unable to generate the pair
-
getKeyPairGenerator
- Returns:
- A
KeyPairGeneratorsuitable for this decoder - Throws:
GeneralSecurityException- If failed to create the generator
-
getSM2ParameterSpec
-