java - 如何使用 bouncy caSTLe 库对 IP 地址进行编码?

标签 java bouncycastle snmp asn.1

我正在尝试使用java实现snmpset, 我正在使用 bouncy caSTLe 版本 1.52 库对 oid 的值进行编码,现在我想对 IP 地址进行编码,我该如何实现呢? 我试过这个:

new GeneralName(GeneralName.iPAddress,"xx.xx.xx.xx");

但是得到一个

snmpInASNParseErrs

错误

更新:

好的,我想我现在已经非常接近正确的答案了,我使用了这个:

InetAddress ip = InetAddress.getByName("xx.xx.xx.xx");
byte[] bytes = ip.getAddress();
v.add(new DERApplicationSpecific(0, new DEROctetString(bytes)));

现在,结果是:

C/x/IpAddress_04_04_0a_00_00_64

仍然需要更多帮助!

最佳答案

最后,我通过以下方式解决了这个问题:

InetAddress ip = InetAddress.getByName(ipv4Address);
byte[] bytes = ip.getAddress();
v.add(new DERApplicationSpecific(0, bytes));

关于java - 如何使用 bouncy caSTLe 库对 IP 地址进行编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45298896/

相关文章:

snmp - SNMP Gauge32 与 Counter32 的定义

centos - Linux (Centos) 上的 SNMP 未显示平均负载

python - 如何检查 python 网络接口(interface)上的数据传输?

Java等待没有锁释放

java - 运行一个新线程,不要等待这个线程完成

java - 在 IntelliJ IDEA 中的上一行和下一行插入的快捷方式(使用 vim 的小 o 和大 O)

java - BouncycaSTLe 签名数据消息中的附加八位字节字符串

c# - 使用 bouncycaSTLe 在 C# 中使用 cryptodome 解密在 python 中加密的 RSA 数据给出错误 block 不正确

java - 如何在 Spring Integration 中对 Rabbit MQ 消息监听器强制执行严格排序?

c# - 生成的签名 X.509 客户端证书无效(没有到其 CA 的证书链)