Do java.security.Key.getEncoded () return DER encoded data?

Do java.security.Key.getEncoded () return data in DER in encoded format?

If not, is there a way?

UPDATE: a key interface containing an RSA private key implementation

+3
source share
1 answer

Depending on the type of key. Most symmetric keys return raw bytes without encoding. Most public keys use ASN.1 / DER encoding.

, . getEncoded . , .

RSA PKCS # 1 PKCS # 8. PKCS # 1 , CRT, .

Sun JCE PKCS # 1, , PKCS # 1,

-- 
-- Representation of RSA private key with information for the CRT algorithm.
--
RSAPrivateKey ::= SEQUENCE {
    version           Version, 
    modulus           INTEGER,  -- n
    publicExponent    INTEGER,  -- e
    privateExponent   INTEGER,  -- d
    prime1            INTEGER,  -- p
    prime2            INTEGER,  -- q
    exponent1         INTEGER,  -- d mod (p-1)
    exponent2         INTEGER,  -- d mod (q-1) 
    coefficient       INTEGER,  -- (inverse of q) mod p
    otherPrimeInfos   OtherPrimeInfos OPTIONAL 
}

Version ::= INTEGER { two-prime(0), multi(1) }
    (CONSTRAINED BY {-- version must be multi if otherPrimeInfos present --})

OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo


OtherPrimeInfo ::= SEQUENCE {
    prime             INTEGER,  -- ri
    exponent          INTEGER,  -- di
    coefficient       INTEGER   -- ti
}
+3

Source: https://habr.com/ru/post/1747595/


All Articles