生成密钥 Java 6 只支持56bit密钥 Bouncy Castle 支持64bit密钥 @return byte[] 二进制密钥 @throws Exception
()
| 125 | * @throws Exception |
| 126 | */ |
| 127 | public static byte[] initKey() throws NoSuchAlgorithmException { |
| 128 | |
| 129 | /* |
| 130 | 实例化密钥生成器 |
| 131 | 若要使用64bit密钥注意替换 将下述代码中的KeyGenerator.getInstance(CIPHER_ALGORITHM); |
| 132 | 替换为KeyGenerator.getInstance(CIPHER_ALGORITHM, "BC"); |
| 133 | */ |
| 134 | KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); |
| 135 | |
| 136 | /*初始化密钥生成器 若要使用64bit密钥注意替换 将下述代码kg.init(56); 替换为kg.init(64);*/ |
| 137 | kg.init(56, new SecureRandom()); |
| 138 | |
| 139 | // 生成秘密密钥 |
| 140 | SecretKey secretKey = kg.generateKey(); |
| 141 | |
| 142 | // 获得密钥的二进制编码形式 |
| 143 | return secretKey.getEncoded(); |
| 144 | } |
| 145 | |
| 146 | } |
nothing calls this directly
no test coverage detected