Corda - 解码 Base58 public 键不起作用
Corda - Decoding Base58 public keys doesn't work
将 Base58 public 密钥解码回 PublicKey
实例似乎不起作用:
parsePublicKeyBase58("DLG9nscvKPbgagoLP7jr4oc5FygazKr7pdADZMGFizmpV8")
Exception in thread "main" java.lang.IllegalArgumentException: failed to construct sequence from byte[]: unknown tag 9 encountered
at org.bouncycastle.asn1.ASN1Sequence.getInstance(Unknown Source)
at org.bouncycastle.asn1.x509.SubjectPublicKeyInfo.getInstance(Unknown Source)
at net.corda.core.crypto.Crypto.decodePublicKey(Crypto.kt:343)
at net.corda.core.utilities.EncodingUtils.parsePublicKeyBase58(EncodingUtils.kt:81)
at test.Program$Companion.main(Program.kt:15)
at test.Program.main(Program.kt)
这是怎么回事?
你遇到了什么错误 – Sneha Damle?
parsePublicKeyBase58("G9nscvKPbgagoLP7jr4oc5FygazKr7pdADZMGFizmpV8")
Exception in thread "main" java.lang.IllegalArgumentException: failed to construct sequence from byte[]: DEF length 31 object truncated by 1
at org.bouncycastle.asn1.ASN1Sequence.getInstance(Unknown Source)
at org.bouncycastle.asn1.x509.SubjectPublicKeyInfo.getInstance(Unknown Source)
at net.corda.core.crypto.Crypto.decodePublicKey(Crypto.kt:343)
at net.corda.core.utilities.EncodingUtils.parsePublicKeyBase58(EncodingUtils.kt:81)
at test.ProgramKt.main(Program.kt:6)
您可能使用了不正确的 Base58 字符串。我执行了以下操作并且有效。
将 Public 密钥编码为 Base58
Base58.encode(party.getOwningKey().getEncoded()).toString();
这给了我字符串 GfHq2tTVk9z4eXgyH7WThpV3Qn7zdCm4cKw8J5x8kVGnVkGtgAmh3KKE7EN4
解码:
PublicKey publicKey = EncodingUtils.parsePublicKeyBase58("GfHq2tTVk9z4eXgyH7WThpV3Qn7zdCm4cKw8J5x8kVGnVkGtgAmh3KKE7EN4");
将 Base58 public 密钥解码回 PublicKey
实例似乎不起作用:
parsePublicKeyBase58("DLG9nscvKPbgagoLP7jr4oc5FygazKr7pdADZMGFizmpV8")
Exception in thread "main" java.lang.IllegalArgumentException: failed to construct sequence from byte[]: unknown tag 9 encountered at org.bouncycastle.asn1.ASN1Sequence.getInstance(Unknown Source) at org.bouncycastle.asn1.x509.SubjectPublicKeyInfo.getInstance(Unknown Source) at net.corda.core.crypto.Crypto.decodePublicKey(Crypto.kt:343) at net.corda.core.utilities.EncodingUtils.parsePublicKeyBase58(EncodingUtils.kt:81) at test.Program$Companion.main(Program.kt:15) at test.Program.main(Program.kt)
这是怎么回事?
你遇到了什么错误 – Sneha Damle?
parsePublicKeyBase58("G9nscvKPbgagoLP7jr4oc5FygazKr7pdADZMGFizmpV8")
Exception in thread "main" java.lang.IllegalArgumentException: failed to construct sequence from byte[]: DEF length 31 object truncated by 1 at org.bouncycastle.asn1.ASN1Sequence.getInstance(Unknown Source) at org.bouncycastle.asn1.x509.SubjectPublicKeyInfo.getInstance(Unknown Source) at net.corda.core.crypto.Crypto.decodePublicKey(Crypto.kt:343) at net.corda.core.utilities.EncodingUtils.parsePublicKeyBase58(EncodingUtils.kt:81) at test.ProgramKt.main(Program.kt:6)
您可能使用了不正确的 Base58 字符串。我执行了以下操作并且有效。
将 Public 密钥编码为 Base58
Base58.encode(party.getOwningKey().getEncoded()).toString();
这给了我字符串 GfHq2tTVk9z4eXgyH7WThpV3Qn7zdCm4cKw8J5x8kVGnVkGtgAmh3KKE7EN4
解码:
PublicKey publicKey = EncodingUtils.parsePublicKeyBase58("GfHq2tTVk9z4eXgyH7WThpV3Qn7zdCm4cKw8J5x8kVGnVkGtgAmh3KKE7EN4");