Class OpenSSHSM2PrivateKeyEntryDecoder
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.AbstractPrivateKeyEntryDecoder<ECPublicKey,ECPrivateKey>
org.apache.sshd.common.config.keys.loader.openssh.OpenSSHSM2PrivateKeyEntryDecoder
- All Implemented Interfaces:
IdentityResourceLoader<ECPublicKey,,ECPrivateKey> KeyEntryResolver<ECPublicKey,,ECPrivateKey> KeyTypeNamesSupport,PrivateKeyEntryDecoder<ECPublicKey,,ECPrivateKey> PrivateKeyEntryResolver
public class OpenSSHSM2PrivateKeyEntryDecoder
extends AbstractPrivateKeyEntryDecoder<ECPublicKey,ECPrivateKey>
OpenSSH SM2 私钥解码器,支持64字节公钥和32字节私钥格式
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final OpenSSHSM2PrivateKeyEntryDecoderstatic final intstatic 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.PrivateKeyEntryResolver
FAILING, IGNORING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecodePrivateKey(SessionContext session, String keyType, FilePasswordProvider passwordProvider, InputStream keyData) encodePrivateKey(SecureByteArrayOutputStream s, ECPrivateKey key, ECPublicKey pubKey) private byte[]encodeRawPublicKey(ECPoint point) 将ECPoint编码为64字节原始格式generateKeyPair(int keySize) static ECParameterSpec获取SM2曲线参数规范private booleanisSM2Curve(ECParameterSpec params) 检查是否为SM2曲线参数private ECPointparseRawPublicKey(byte[] pubKey) 解析64字节原始公钥数据为ECPointprivate byte[]toUnsignedBytes(BigInteger bigInt, int length) 将BigInteger转换为固定长度的无符号字节数组Methods 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.PrivateKeyEntryDecoder
decodePrivateKey, decodePrivateKey, decodePrivateKey, isPublicKeyRecoverySupported, recoverPublicKey, resolve
-
Field Details
-
SM2_KEY_TYPE
- See Also:
-
PUBLIC_KEY_LENGTH
public static final int PUBLIC_KEY_LENGTH- See Also:
-
INSTANCE
-
-
Constructor Details
-
OpenSSHSM2PrivateKeyEntryDecoder
public OpenSSHSM2PrivateKeyEntryDecoder()
-
-
Method Details
-
getSM2ParameterSpec
获取SM2曲线参数规范 -
decodePrivateKey
public ECPrivateKey decodePrivateKey(SessionContext session, String keyType, FilePasswordProvider passwordProvider, InputStream keyData) throws IOException, GeneralSecurityException - Parameters:
session- TheSessionContextfor invoking this load command - may benullif not invoked within a session context (e.g., offline tool or session unknown).keyType- The reported / encode key typepasswordProvider- TheFilePasswordProviderto use in case the data is encrypted - may benullif no encrypted data is expectedkeyData- The key data bytes stream positioned after the key type decoding and making sure it is one of the supported types- Returns:
- The decoded
PrivateKey - Throws:
IOException- If failed to read from the data streamGeneralSecurityException- If failed to generate the key
-
parseRawPublicKey
解析64字节原始公钥数据为ECPoint -
encodePrivateKey
public String encodePrivateKey(SecureByteArrayOutputStream s, ECPrivateKey key, ECPublicKey pubKey) throws IOException Description copied from interface:PrivateKeyEntryDecoder- Parameters:
s- TheSecureByteArrayOutputStreamto write the data to.key- ThePrivateKey- may not benullpubKey- ThePublicKeybelonging to the private key - must be non-nullifpublic key recoveryis not supported- Returns:
- The key type value - one of the
KeyTypeNamesSupport.getSupportedKeyTypes()ornullif encoding not supported - Throws:
IOException- If failed to generate the encoding
-
encodeRawPublicKey
将ECPoint编码为64字节原始格式 -
toUnsignedBytes
将BigInteger转换为固定长度的无符号字节数组 -
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
-
isSM2Curve
检查是否为SM2曲线参数 -
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
-