2012-05-31 49 views
8

我想知道在Java中是否存在JKS密鑰存儲格式的官方規格?我想寫一個從/到PKCS#12的轉換器,但不能用Java編寫,所以不幸的是,keytool或Java代碼不是一種選擇。JKS密鑰存儲格式的規格

在十六進制編輯器中查看一個告訴我,它可能不是ASN.1。在開始深入研究OpenJDK之前,試圖對這種格式進行逆向工程,有沒有人知道是否存在規範?到目前爲止我找不到任何東西,任何幫助將不勝感激!

回答

12

我認爲你應該從JDK sources開始你的研究。那裏有一些非常有用的評論。 例如

/* 
     * KEYSTORE FORMAT: 
     * 
     * Magic number (big-endian integer), 
     * Version of this file format (big-endian integer), 
     * 
     * Count (big-endian integer), 
     * followed by "count" instances of either: 
     * 
     *  { 
     *  tag=1 (big-endian integer), 
     *  alias (UTF string) 
     *  timestamp 
     *  encrypted private-key info according to PKCS #8 
     *   (integer length followed by encoding) 
     *  cert chain (integer count, then certs; for each cert, 
     *   integer length followed by encoding) 
     *  } 
     * 
     * or: 
     * 
     *  { 
     *  tag=2 (big-endian integer) 
     *  alias (UTF string) 
     *  timestamp 
     *  cert (integer length followed by encoding) 
     *  } 
     * 
     * ended by a keyed SHA1 hash (bytes only) of 
     *  { password + whitener + preceding body } 
     */