io.proximax.core.crypto.PublicKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-xpx-chain-sdk Show documentation
Show all versions of java-xpx-chain-sdk Show documentation
The ProximaX Sirius Chain Java SDK is a Java library for interacting with the Sirius Blockchain.
The newest version!
/*
* Copyright 2018 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.proximax.core.crypto;
import java.util.Arrays;
import io.proximax.core.utils.HexEncoder;
/**
* Represents a public key.
*/
public class PublicKey {
private final byte[] value;
/**
* Creates a new public key.
*
* @param bytes The raw public key value.
*/
public PublicKey(final byte[] bytes) {
this.value = bytes;
}
/**
* Creates a public key from a hex string.
*
* @param hex The hex string.
* @return The new public key.
*/
public static PublicKey fromHexString(final String hex) {
try {
return new PublicKey(HexEncoder.getBytes(hex));
} catch (final IllegalArgumentException e) {
throw new CryptoException(e);
}
}
/**
* Gets the raw public key value.
*
* @return The raw public key value.
*/
public byte[] getRaw() {
return this.value;
}
/**
* get public key as a hexadecimal string
*
* @return hexadecimal string representing the public key
*/
public String getHexString() {
return HexEncoder.getString(getRaw());
}
@Override
public int hashCode() {
return Arrays.hashCode(this.value);
}
@Override
public boolean equals(final Object obj) {
if (obj == null || !(obj instanceof PublicKey)) {
return false;
}
final PublicKey rhs = (PublicKey) obj;
return Arrays.equals(this.value, rhs.value);
}
@Override
public String toString() {
return HexEncoder.getString(this.value);
}
}