Package nxt.crypto
Class SecretSharingGenerator
java.lang.Object
nxt.crypto.SecretSharingGenerator
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringGiven minPieces pieces out of totalPieces of a secretPhrase, combine the pieces into the original phrase.* Pieces are formatted as [version]:[split id]:[total pieces]:[minimum pieces]:[prime field size or zero]:[piece number]:[piece content]static byte[]combinePrivateKey(String[] encodedSecretPhrasePieces) Given minPieces pieces out of totalPieces of a privateKey, combine the pieces into the original.static BigIntegergetModPrime(byte[] privateKey) Given a private key calculate the modulo prime finite field size which is sufficiently large to split the key.static BigIntegergetModPrime(String secretPhrase) Given a secret phrase calculate the modulo prime finite field size which is sufficiently large to split the shared secrets.static booleanisPrivateKeySecret(String[] encodedSecretPhrasePieces) static String[]split(byte[] privateKey, int totalPieces, int minPieces, BigInteger declaredModePrime) Given a secret byte array split it into totalPieces pieces where each minPieces of them are enough to reproduce the secret.static String[]split(String secretPhrase, int totalPieces, int minPieces, BigInteger declaredModePrime) Given a secretPhrase split it into totalPieces pieces where each minPieces of them are enough to reproduce the secret.
-
Constructor Details
-
SecretSharingGenerator
public SecretSharingGenerator()
-
-
Method Details
-
split
public static String[] split(String secretPhrase, int totalPieces, int minPieces, BigInteger declaredModePrime) Given a secretPhrase split it into totalPieces pieces where each minPieces of them are enough to reproduce the secret. If the secret phrase a is valid BIP39 mnemonic using the english wordlist, it is converted to the corresponding entropy between 128 and 256 bits and a byte to store the number of words on the original mnemonic. If the secret phrase is 12 words from the legacy list, the secret is converted into 128 bit number which is very compact. Otherwise the secret phrase is converted to bytes using UTF8 then to a BigInteger. Every one of these cases is codified into the version integer of the resulting pieces. Pieces are returned with a piece number followed by : and the piece content. The piece number is required when reproducing the secret.- Parameters:
secretPhrase- the secret phrasetotalPieces- the number of generated piecesminPieces- the number of pieces needed to reproduce the secret phrasedeclaredModePrime- the modulo prime used for secret sharing calculations. Specify BigInteger.ZERO to calculate automatically- Returns:
- the secret pieces
-
split
public static String[] split(byte[] privateKey, int totalPieces, int minPieces, BigInteger declaredModePrime) Given a secret byte array split it into totalPieces pieces where each minPieces of them are enough to reproduce the secret. Pieces are returned with a piece number followed by : and the piece content. The piece number is required when reproducing the secret.- Parameters:
privateKey- the secret byte arraytotalPieces- the number of generated piecesminPieces- the number of pieces needed to reproduce the secret phrasedeclaredModePrime- the modulo prime used for secret sharing calculations. Specify BigInteger.ZERO to calculate automatically- Returns:
- the secret pieces
-
combinePrivateKey
Given minPieces pieces out of totalPieces of a privateKey, combine the pieces into the original. Pieces are formatted as [version]:[split id]:[total pieces]:[minimum pieces]:[prime field size or zero]:[piece number]:[piece content]- Parameters:
encodedSecretPhrasePieces- the pieces of the private key formatted as specified above- Returns:
- the reproduced private key
-
combine
Given minPieces pieces out of totalPieces of a secretPhrase, combine the pieces into the original phrase.* Pieces are formatted as [version]:[split id]:[total pieces]:[minimum pieces]:[prime field size or zero]:[piece number]:[piece content]- Parameters:
encodedSecretPhrasePieces- the pieces of the secret phrase formatted as specified above- Returns:
- the reproduced secret phrase
-
isPrivateKeySecret
-
getModPrime
Given a secret phrase calculate the modulo prime finite field size which is sufficiently large to split the shared secrets. The specific encoding (version) used is guessed trying to find the best one.- Parameters:
secretPhrase- the secret phrase- Returns:
- the prime number representing the finite field size
-
getModPrime
Given a private key calculate the modulo prime finite field size which is sufficiently large to split the key.- Parameters:
privateKey- the private key- Returns:
- the prime number representing the finite field size
-