Search code examples
javarsagoogle-data-api

how to generate rsa key for gdata java api?


I want to access data feed of my Google Data. I am using gdata private library. How do I generate RSA-Key using Java Keytool ? How do I convert that key to .pk8 format ?


Solution

  • How to generate the RSA key can be found in the Google API documentation:

    http://code.google.com/intl/de-DE/apis/gdata/docs/auth/authsub.html#Registered

    # Generate the RSA keys and certificate
    openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj \
      '/C=US/ST=CA/L=Mountain View/CN=www.example.com' -keyout \
      myrsakey.pem -out /tmp/myrsacert.pem
    

    Using Java keytools is very similar.

    First, generate the key pair:

    keytool -genkey -alias myrsakey -keyalg RSA -validity 365 \
     -dname="CN=US, ST=CA/L=Mountain View, CN=www.example.com" \
     -keystore mykeystore.jks
    

    Then you can export the certificate:

    keytool -keystore mykeystore.jks -export -alias myrsakey -rfc -file key.pem
    

    AFAIK private keys can not be exported directly via keytool.