Package org.bitcoinj.base
Class Bech32
- java.lang.Object
- 
- org.bitcoinj.base.Bech32
 
- 
 public class Bech32 extends java.lang.ObjectImplementation of the Bech32 encoding. Used in the implementation ofSegwitAddressand also provides an API for encoding/decoding arbitrary Bech32 data. To parse Bech32 Bitcoin addresses, useAddressParser. To encode arbitrary Bech32 data, seeencodeBytes(Encoding, String, byte[]). To decode arbitrary Bech32 strings, seedecodeBytes(String, String, Encoding)ordecode(String).Based on the original Coinomi implementation. 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classBech32.Bech32BytesBinary data in 5-bits-per-byte format as used in Bech32 encoding/decoding.static classBech32.Bech32DataBech32 data in 5-bit byte format withBech32.Encodingand human-readable part (HRP) information.static classBech32.EncodingEnumeration of known Bech32 encoding format types: Bech32 and Bech32m.
 - 
Constructor SummaryConstructors Constructor Description Bech32()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static Bech32.Bech32Datadecode(java.lang.String str)Decode a Bech32 string.static byte[]decodeBytes(java.lang.String bech32, java.lang.String expectedHrp, Bech32.Encoding expectedEncoding)Decode a Bech32 string to a byte array.static java.lang.Stringencode(Bech32.Bech32Data bech32)Encode a Bech32 string.static java.lang.Stringencode(Bech32.Encoding encoding, java.lang.String hrp, Bech32.Bech32Bytes values)Encode a Bech32 string.static java.lang.StringencodeBytes(Bech32.Encoding encoding, java.lang.String hrp, byte[] bytes)Encode a byte array to a Bech32 string
 
- 
- 
- 
Method Detail- 
encodeBytespublic static java.lang.String encodeBytes(Bech32.Encoding encoding, java.lang.String hrp, byte[] bytes) Encode a byte array to a Bech32 string- Parameters:
- encoding- Desired encoding Bech32 or Bech32m
- hrp- human-readable part to use for encoding
- bytes- Arbitrary binary data (8-bits per byte)
- Returns:
- A Bech32 string
 
 - 
decodeBytespublic static byte[] decodeBytes(java.lang.String bech32, java.lang.String expectedHrp, Bech32.Encoding expectedEncoding)Decode a Bech32 string to a byte array.- Parameters:
- bech32- A Bech32 format string
- expectedHrp- Expected value for the human-readable part
- expectedEncoding- Expected encoding
- Returns:
- Decoded value as byte array (8-bits per byte)
- Throws:
- AddressFormatException- if unexpected hrp or encoding
 
 - 
encodepublic static java.lang.String encode(Bech32.Bech32Data bech32) Encode a Bech32 string.- Parameters:
- bech32- Contains 5-bits/byte data, desired encoding and human-readable part
- Returns:
- A string containing the Bech32-encoded data
 
 - 
encodepublic static java.lang.String encode(Bech32.Encoding encoding, java.lang.String hrp, Bech32.Bech32Bytes values) Encode a Bech32 string.- Parameters:
- encoding- The requested encoding
- hrp- The requested human-readable part
- values- Binary data in 5-bit per byte format
- Returns:
- A string containing the Bech32-encoded data
 
 - 
decodepublic static Bech32.Bech32Data decode(java.lang.String str) throws AddressFormatException Decode a Bech32 string.To get the fully-decoded data, call Bech32.Bech32Bytes.decode5to8()on the returnedBech32Data.- Parameters:
- str- A string containing Bech32-encoded data
- Returns:
- An object with the detected encoding, hrp, and decoded data (in 5-bit per byte format)
- Throws:
- AddressFormatException- if the string is invalid
 
 
- 
 
-