公钥、私钥现已统一使用标准 PEM 格式显示
This commit is contained in:
1 parent
410d777c0b
commit
e6ad3bd85c
2 files changed
+9
-3
No files matched your search
@@ -60,8 +60,8 @@ public class AppsServiceImpl extends ServiceImpl<AppsMapper, AppsPlus> implement
|
||||
generator.initialize(RSA_KEY_SIZE);
|
||||
KeyPair keyPair = generator.generateKeyPair();
|
||||
return new AppKeyPairResult("RSA", RSA_KEY_SIZE,
|
||||
Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded()),
|
||||
Base64.getEncoder().encodeToString(keyPair.getPrivate().getEncoded()));
|
||||
toPem("PUBLIC KEY", keyPair.getPublic().getEncoded()),
|
||||
toPem("PRIVATE KEY", keyPair.getPrivate().getEncoded()));
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("RSA 密钥对生成失败", e);
|
||||
}
|
||||
@@ -439,6 +439,12 @@ public class AppsServiceImpl extends ServiceImpl<AppsMapper, AppsPlus> implement
|
||||
}
|
||||
}
|
||||
|
||||
/** 将 DER 密钥编码为标准 PEM,正文固定每行 64 个字符。 */
|
||||
private String toPem(String type, byte[] encodedKey) {
|
||||
String body = Base64.getMimeEncoder(64, new byte[] { '\n' }).encodeToString(encodedKey);
|
||||
return "-----BEGIN " + type + "-----\n" + body + "\n-----END " + type + "-----";
|
||||
}
|
||||
|
||||
private void validateIds(Long[] ids) {
|
||||
if (ids == null || ids.length == 0) throw new CustomException("请选择要删除的商户");
|
||||
for (Long id : ids) if (id == null) throw new CustomException("商户 ID 不能为空");
|
||||
|
||||
Reference in new issue
Block a user