跳至主要内容
本页面使用机器翻译自英语,可能包含错误或不清楚的语言。如需最准确的信息,请参阅英文原文。由于更新频繁,部分内容可能与英文原文有出入。请加入我们在 Crowdin 上的努力,帮助我们改进本页面的翻译。 (Crowdin translation page, Contributing guide)

Address

用于压缩公钥的工具。

从 Web3j 和 kaia 库(web3j-ext)导入必要的类

要将 "压缩公钥 "转换为 {x, y}格式的 "AccountPublicKey",请使用 AccountKeyPublicUtils.decompressKey

要将 AccountKeyPublic 压缩为 Compressed Public Key 字符串,请使用 AccountKeyPublicUtils.toCompressedPublicKey

PublicKeyUtilsExample.java

package org.web3j.example.utils;
import org.web3j.crypto.transaction.account.AccountKeyPublic;
import org.web3j.utils.AccountKeyPublicUtils;
public class PublicKeyUtilsExample {
public static void main(String[] args) {
System.out.println("From compressed public key to AccountKeyPublic");
System.out.println(AccountKeyPublicUtils.decompressKey("03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd"));
System.out.println("From x,y to compressed public key");
AccountKeyPublic publicKey= AccountKeyPublic.create("0xdc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd","0xaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79");
System.out.println(AccountKeyPublicUtils.toCompressedPublicKey(publicKey.getPublicKey()));
}
}

output

❯ java PublicKeyUtilsExample.java
From compressed public key to AccountKeyPublic
AccountKeyPublic x : 0xdc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd / y : 0xaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79
From x,y to compressed public key
03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd

让这个页面变得更好