diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35797c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,235 @@ + +# don't forget share .gitignore located in project root path +!.gitignore + + +######## programming lang related ignore +####################################################################################################### +####################################################################################################### +####################################################################################################### + +## .gitignore for java +## https://raw.githubusercontent.com/github/gitignore/master/Java.gitignore + +*.class + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +!/lib/*.jar +*.war +*.ear +*.zip +*.zip.sha1 + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +## .gitignore for java web +# older plugin install locations +/plugins +/web-app/plugins +/web-app/WEB-INF/classes +**/classes/ + +**/classes/ +**/WEB-INF/classes/ +**/WEB-INF/tmp/ +**/WEB-INF/work/ +*__jsp.java +*__jsp.java.smap + +######## state info on running: logs or mem-db +####################################################################################################### +####################################################################################################### +####################################################################################################### + +# default HSQL database files for production mode +/prodDb.* + +# general HSQL database files +*Db.properties +*Db.script + +# logs +/stacktrace.log +/test/reports +/logs +/log +*.log +*.log.* + + +######## maven & ant related ignore +####################################################################################################### +####################################################################################################### +####################################################################################################### + +# .gitignore for maven +target/ +*.releaseBackup + +# .gitignore for ant +build/ +out/ + +# older plugin install locations +/plugins +/web-app/plugins +/web-app/WEB-INF/classes + +######## IDE related ignore +####################################################################################################### +####################################################################################################### + +## .gitignore for eclipse +#################################### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ +##################################### + + +## .gitignore for intellij +##################################### + +*.iml +*.ipr +*.iws +.idea/ + +##################################### + + + +######## OS related ignore +####################################################################################################### +####################################################################################################### + +## .gitignore for windows +## https://raw.githubusercontent.com/github/gitignore/master/Global/Windows.gitignore +#################################### +# Windows thumbnail cache files +Thumbs.dtignoreb +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk +################################## + + +## .gitignore for mac os x +## https://raw.githubusercontent.com/github/gitignore/master/Global/macOS.gitignore +################################### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk +######################################### + + +## .gitignore for linux +## https://raw.githubusercontent.com/github/gitignore/master/Global/Linux.gitignore +######################################### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* +######################################## diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e5123e --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# display pem key file in bigint hex format + +## how to run + +``java -jar pemkey-0.1.0-all.jar $path-to-file.pem`` + +for help, run ``java -jar pemkey-0.1.0-all.jar`` + +for example ``java -jar pemkey-0.1.0-all.jar /tmp/passport-pri-1024-test.pem`` + +**NOTE** + +a precompiled package is available at [v0.1.0 Releases](https://github.com/downgoon/pemkey/releases/tag/v0.1.0), you can go to this page and download it directly. + +## how to build + + git clone https://github.com/downgoon/pemkey.git + cd pemkey + mvn clean package + java -jar target/pemkey-0.1.0-all.jar $path-to-file.pem + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..798d6b4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,103 @@ + + 4.0.0 + + io.downgoon.tools + pemkey + 0.1.0 + jar + + pemkey + http://maven.apache.org + + + UTF-8 + + + + + + com.github.downgoon + jresty-security + 0.0.1-SNAPSHOT + + + + junit + junit + 4.4 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + ${project.build.sourceEncoding} + true + true + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.9 + + true + true + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.0 + + + package + + shade + + + + + io.downgoon.tools.Pem2Bigint + + + false + true + all + + + *:* + + + false + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + + diff --git a/src/main/java/io/downgoon/tools/Pem2Bigint.java b/src/main/java/io/downgoon/tools/Pem2Bigint.java new file mode 100644 index 0000000..9aff2c7 --- /dev/null +++ b/src/main/java/io/downgoon/tools/Pem2Bigint.java @@ -0,0 +1,62 @@ +package io.downgoon.tools; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.security.Key; + +import com.github.downgoon.jresty.commons.security.RsaKeyIO; + +public class Pem2Bigint { + + public static void main(String[] args) throws Exception { + if (args.length < 1) { + System.out.println("Usage: Pem2Bigint "); + System.out.println("Attachment: How to generate key pairs ? "); + System.out.println("generate prikey > openssl genrsa -out prikey.pem 1024"); + System.out.println(" export pukkey > openssl rsa -in prikey.pem -pubout -out pubkey.pem"); + System.exit(400); + } + + File pemFile = new File(args[0]); + boolean isPri = isPrivateKey(pemFile); + + Key key = null; + if (isPri) { + key = RsaKeyIO.importPrivateFrPem(pemFile); + } else { + key = RsaKeyIO.importPublicFrPem(pemFile); + } + + System.out.println(key); + + } + + private static boolean isPrivateKey(File pemFile) throws Exception { + String content = readFileContent(pemFile); + return content.indexOf("PRIVATE KEY") != -1; + } + + private static String readFileContent(File file) throws Exception { + StringBuffer content = new StringBuffer(); + BufferedReader reader = null; + + try { + reader = new BufferedReader(new FileReader(file)); + String line = reader.readLine(); + while (line != null) { + content.append(line); + content.append("\n"); + line = reader.readLine(); + } + return content.toString(); + + } finally { + if (reader != null) { + reader.close(); + } + } + + } + +}