title: How to decode IPFS private and public key in DER/PEM format?
body: <p>how to decode IPFS private and public key in DER/PEM format that can work with the pycryptodome library(for Python 3)? I get the keys from the IPFS configuration file as strings, so I will not explain this process here.</p>
  
  <p>What I'm trying to do:</p>
  
  <pre><code>import base64, Crypto
  
  publicKey = "CAASpgIwgE ... jkupAgMBAAE="
  privateKey = "CAASqQkwgg ... Xmzva/Km7A=="
  
  publicKey = base64.b64decode(publicKey)
  key = Crypto.PublicKey.RSA.import_key(publicKey)
  crypter = Crypto.Cipher.PKCS1_OAEPPKCS1_OAEP.new(key)
  encryptedData = crypter.encrypt(data.encode())
  result = base64.b64encode(encryptedData).decode()
  </code></pre>
  
  <p>I get the following exception:</p>
  
  <pre><code>key = Crypto.PublicKey.RSA.importKey(publicKey)
    File "/usr/local/lib/python3.6/site-packages/Crypto/PublicKey/RSA.py", line 754, in import_key
      raise ValueError("RSA key format is not supported")
  </code></pre>
  
  <p>Similar problem with privateKey. In what format is the key and how to convert it to an acceptable format? </p>
  
  <p>import_key function source code is there: <a href="https://github.com/Legrandin/pycryptodome/blob/master/lib/Crypto/PublicKey/RSA.py#L682" rel="nofollow noreferrer">https://github.com/Legrandin/pycryptodome/blob/master/lib/Crypto/PublicKey/RSA.py#L682</a></p>