如何在Java中解码DER编码的字符串? [英] How do I decode a DER encoded string in Java?

查看:2889
本文介绍了如何在Java中解码DER编码的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数字证书中读取自定义扩展程序。我知道值是在DER中编码的GeneralString。有没有一种简单的方法来正确解码它并获得Java String?我尝试了以下内容,但's'包含一些编码元数据作为字符串开头的垃圾字符。

I'm trying to read a custom extension from a digital certificate. I know the value is a GeneralString encoded in DER. Is there an easy way to correctly decode it and get a Java String? I tried the following, but 's' includes some of the encoding metadata as junk characters at the start of the string.

byte[] ext = cert.getExtensionValue("1.2.3.4");
String s= new String(ext);
System.out.println(s);

有没有快速简便的方法呢?或者我真的需要使用一些完整的ASN.1库吗?

Is there a quick and easy way to do this? Or do I really need to use some full fledged ASN.1 library?

谢谢!

推荐答案

BouncyCastle (除此之外):


用于读写编码的ASN.1对象的库。

A library for reading and writing encoded ASN.1 objects.

这篇关于如何在Java中解码DER编码的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆