-
| Could you show me how to extract a public RSA key from a private key? I looked but couldn’t find the steps. | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            whyoleg
          
      
      
        Sep 18, 2025 
      
    
    Replies: 1 comment 1 reply
-
| Unfortunately, at this point, there is no API for that. But, for RSA, you can do it using  private fun getPrivateKey(
    privateKey: RSA.PSS.PrivateKey,
    digest: CryptographyAlgorithmId<Digest>,
): RSA.PSS.PublicKey {
    val decoder = CryptographyProvider.Default.get(RSA.PSS).publicKeyDecoder(digest)
    val rsaPrivateKey = Der.decodeFromByteArray<RsaPrivateKey>(
        privateKey.encodeToByteArrayBlocking(RSA.PrivateKey.Format.DER.PKCS1)
    )
    val rsaPublicKey = RsaPublicKey(
        modulus = rsaPrivateKey.modulus,
        publicExponent = rsaPrivateKey.publicExponent,
    )
    return decoder.decodeFromByteArrayBlocking(
        format = RSA.PublicKey.Format.DER.PKCS1,
        bytes = Der.encodeToByteArray(rsaPublicKey)
    )
}I believe it should be possible to support this in the library itself. I've added it to my shortlist. | 
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
      Answer selected by
        whyoleg
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Unfortunately, at this point, there is no API for that. But, for RSA, you can do it using
cryptography-serialization-asn1-modulesmodels. It could look like this: