本文整理汇总了Java中org.bouncycastle.pqc.math.linearalgebra.ByteUtils类的典型用法代码示例。如果您正苦于以下问题:Java ByteUtils类的具体用法?Java ByteUtils怎么用?Java ByteUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteUtils类属于org.bouncycastle.pqc.math.linearalgebra包,在下文中一共展示了ByteUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Vault
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public Vault (Map<String, String> keys) throws BCSAPIException, ValidationException
{
for ( Map.Entry<String, String> keyEntry : keys.entrySet () )
{
publicKeys.put (keyEntry.getKey (), new ECPublicKey (ByteUtils.fromHexString (keyEntry.getValue ()), true));
}
log.info ("Vault address: " + getVaultAddress ());
this.accountManager = new AM ();
accountManager.setCreated (new DateTime (2013, 12, 1, 0, 0).getMillis ());
accountManager.addAccountListener (new AccountListener ()
{
@Override
public void accountChanged (AccountManager account, Transaction t)
{
log.info ("New account balance " + fromSatoshi (account.getBalance ()) + " " +
fromSatoshi (account.getConfirmed ()) + " confrirmed " +
fromSatoshi (account.getChange ()) + " change " +
fromSatoshi (account.getReceiving ()) + " receiving");
}
});
}
示例2: send_v2
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public String send_v2(String fee){
// collect parameters
TimeInstant timeInstant = new SystemTimeProvider().getCurrentTime();
KeyPair senderKeyPair = new KeyPair(PrivateKey.fromHexString(this.privateKey));
Account senderAccount = new Account(senderKeyPair);
Account multisigAccount = new Account(Address.fromPublicKey(PublicKey.fromHexString(this.multisigPublicKey)));
Hash otherTransactionHash = Hash.fromHexString(this.innerTransactionHash);
// create multisig signature transaction
MultisigSignatureTransaction multisigSignatureTransaction = new MultisigSignatureTransaction(
timeInstant, senderAccount, multisigAccount, otherTransactionHash);
if(fee==null){
TransactionFeeCalculatorAfterForkForApp feeCalculator = new TransactionFeeCalculatorAfterForkForApp();
multisigSignatureTransaction.setFee(feeCalculator.calculateMinimumFee(multisigSignatureTransaction));
} else {
multisigSignatureTransaction.setFee(Amount.fromNem(0));
}
multisigSignatureTransaction.setDeadline(timeInstant.addHours(23));
multisigSignatureTransaction.sign();
JSONObject params = new JSONObject();
final byte[] data = BinarySerializer.serializeToBytes(multisigSignatureTransaction.asNonVerifiable());
params.put("data", ByteUtils.toHexString(data));
params.put("signature", multisigSignatureTransaction.getSignature().toString());
return HttpClientUtils.post(Constants.URL_TRANSACTION_ANNOUNCE, params.toString());
}
示例3: generateM1
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public static byte[] generateM1(
Digest digest,
BigInteger N,
BigInteger g,
byte[] ephemeralKeyA,
byte[] ephemeralKeyB,
byte[] key,
byte[] salt, // s
byte[] identity) {
// M1 = H(H(N) XOR H(g) | H(I) | s | A | B | K)
int length = length(N);
// hI = H(I)
byte[] hI = hash(digest, identity);
// tmp = H(N) XOR H(g)
byte[] hNxhG = ByteUtils.xor(hash(digest, padded(N, length)), hash(digest, padded(g, length)));
return hash(digest, hNxhG, hI, salt, ephemeralKeyA, ephemeralKeyB, key);
}
示例4: send_v2
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public String send_v2(String recipient, long amount, String messagePayload, MosaicId mosaicId, Quantity mosaicQuantity, String fee){
// collect parameters
TimeInstant timeInstant = new SystemTimeProvider().getCurrentTime();
KeyPair senderKeyPair = new KeyPair(PrivateKey.fromHexString(this.privateKey));
Account senderAccount = new Account(senderKeyPair);
Account recipientAccount = new Account(Address.fromEncoded(recipient));
// add message and mosaic
TransferTransactionAttachment attachment = new TransferTransactionAttachment();
if(!"".equals(messagePayload.trim())){
PlainMessage message = new PlainMessage(messagePayload.getBytes());
attachment.setMessage(message);
}
if(mosaicId!=null && mosaicQuantity!=null){
attachment.addMosaic(mosaicId, mosaicQuantity);
}
if(attachment.getMessage()==null && attachment.getMosaics().size()==0){
attachment = null;
}
// create transaction
TransferTransaction transaction = new TransferTransaction(2, timeInstant, senderAccount, recipientAccount, Amount.fromNem(amount), attachment);
// ignore fee or not
if(fee==null){
TransactionFeeCalculatorAfterForkForApp feeCalculator = new TransactionFeeCalculatorAfterForkForApp();
transaction.setFee(feeCalculator.calculateMinimumFee(transaction));
} else {
transaction.setFee(Amount.fromNem(0));
}
transaction.setDeadline(timeInstant.addHours(23));
transaction.sign();
JSONObject params = new JSONObject();
final byte[] data = BinarySerializer.serializeToBytes(transaction.asNonVerifiable());
params.put("data", ByteUtils.toHexString(data));
params.put("signature", transaction.getSignature().toString());
return HttpClientUtils.post(Constants.URL_TRANSACTION_ANNOUNCE, params.toString());
}
示例5: getSha3Hash
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public static String getSha3Hash(String data) {
String trimmedData = trimNewLines(data);
byte[] dataBytes = trimmedData.getBytes();
SHA3Digest md = new SHA3Digest(256);
md.reset();
md.update(dataBytes, 0, dataBytes.length);
byte[] hashedBytes = new byte[256 / 8];
md.doFinal(hashedBytes, 0);
String sha3Hash = ByteUtils.toHexString(hashedBytes);
return sha3Hash;
}
示例6: generateRandomKey
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public RandomKey generateRandomKey () throws ValidationException
{
byte[] entropy = new byte[16];
random.nextBytes (entropy);
return new RandomKey (BIP39.encode (entropy, ""),
ByteUtils.toHexString (ExtendedKey.create (entropy).getKey (0).getPublic ()));
}
示例7: getKeys
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public List<NamedKey> getKeys ()
{
List<NamedKey> keys = new ArrayList<> ();
for ( Map.Entry<String, ECPublicKey> e : publicKeys.entrySet () )
{
keys.add (new NamedKey (e.getKey (), ByteUtils.toHexString (e.getValue ().getPublic ())));
}
return keys;
}
示例8: messageEncrypt
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public byte[] messageEncrypt(byte[] input)
throws Exception
{
int kDiv8 = k >> 3;
// generate random r of length k div 8 bytes
byte[] r = new byte[kDiv8];
sr.nextBytes(r);
// generate random vector r' of length k bits
GF2Vector rPrime = new GF2Vector(k, sr);
// convert r' to byte array
byte[] rPrimeBytes = rPrime.getEncoded();
// compute (input||r)
byte[] mr = ByteUtils.concatenate(input, r);
// compute H(input||r)
messDigest.update(mr, 0, mr.length);
byte[] hmr = new byte[messDigest.getDigestSize()];
messDigest.doFinal(hmr, 0);
// convert H(input||r) to error vector z
GF2Vector z = Conversions.encode(n, t, hmr);
// compute c1 = E(rPrime, z)
byte[] c1 = McElieceCCA2Primitives.encryptionPrimitive((McElieceCCA2PublicKeyParameters)key, rPrime,
z).getEncoded();
// get PRNG object
DigestRandomGenerator sr0 = new DigestRandomGenerator(new SHA1Digest());
// seed PRNG with r'
sr0.addSeedMaterial(rPrimeBytes);
// generate random c2
byte[] c2 = new byte[input.length + kDiv8];
sr0.nextBytes(c2);
// XOR with input
for (int i = 0; i < input.length; i++)
{
c2[i] ^= input[i];
}
// XOR with r
for (int i = 0; i < kDiv8; i++)
{
c2[input.length + i] ^= r[i];
}
// return (c1||c2)
return ByteUtils.concatenate(c1, c2);
}
示例9: messageDecrypt
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public byte[] messageDecrypt(byte[] input)
throws Exception
{
int c1Len = (n + 7) >> 3;
int c2Len = input.length - c1Len;
// split cipher text (c1||c2)
byte[][] c1c2 = ByteUtils.split(input, c1Len);
byte[] c1 = c1c2[0];
byte[] c2 = c1c2[1];
// decrypt c1 ...
GF2Vector c1Vec = GF2Vector.OS2VP(n, c1);
GF2Vector[] c1Dec = McElieceCCA2Primitives.decryptionPrimitive((McElieceCCA2PrivateKeyParameters)key,
c1Vec);
byte[] rPrimeBytes = c1Dec[0].getEncoded();
// ... and obtain error vector z
GF2Vector z = c1Dec[1];
// get PRNG object
DigestRandomGenerator sr0 = new DigestRandomGenerator(new SHA1Digest());
// seed PRNG with r'
sr0.addSeedMaterial(rPrimeBytes);
// generate random sequence
byte[] mrBytes = new byte[c2Len];
sr0.nextBytes(mrBytes);
// XOR with c2 to obtain (m||r)
for (int i = 0; i < c2Len; i++)
{
mrBytes[i] ^= c2[i];
}
// compute H(m||r)
messDigest.update(mrBytes, 0, mrBytes.length);
byte[] hmr = new byte[messDigest.getDigestSize()];
messDigest.doFinal(hmr, 0);
// compute Conv(H(m||r))
c1Vec = Conversions.encode(n, t, hmr);
// check that Conv(H(m||r)) = z
if (!c1Vec.equals(z))
{
throw new Exception("Bad Padding: Invalid ciphertext.");
}
// split (m||r) to obtain m
int kDiv8 = k >> 3;
byte[][] mr = ByteUtils.split(mrBytes, c2Len - kDiv8);
// return plain text m
return mr[0];
}
示例10: messageEncrypt
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public byte[] messageEncrypt(byte[] input)
throws Exception
{
// generate random vector r of length k bits
GF2Vector r = new GF2Vector(k, sr);
// convert r to byte array
byte[] rBytes = r.getEncoded();
// compute (r||input)
byte[] rm = ByteUtils.concatenate(rBytes, input);
// compute H(r||input)
messDigest.update(rm, 0, rm.length);
byte[] hrm = new byte[messDigest.getDigestSize()];
messDigest.doFinal(hrm, 0);
// convert H(r||input) to error vector z
GF2Vector z = Conversions.encode(n, t, hrm);
// compute c1 = E(r, z)
byte[] c1 = McElieceCCA2Primitives.encryptionPrimitive((McElieceCCA2PublicKeyParameters)key, r, z)
.getEncoded();
// get PRNG object
DigestRandomGenerator sr0 = new DigestRandomGenerator(new SHA1Digest());
// seed PRNG with r'
sr0.addSeedMaterial(rBytes);
// generate random c2
byte[] c2 = new byte[input.length];
sr0.nextBytes(c2);
// XOR with input
for (int i = 0; i < input.length; i++)
{
c2[i] ^= input[i];
}
// return (c1||c2)
return ByteUtils.concatenate(c1, c2);
}
示例11: messageDecrypt
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public byte[] messageDecrypt(byte[] input)
throws Exception
{
int c1Len = (n + 7) >> 3;
int c2Len = input.length - c1Len;
// split ciphertext (c1||c2)
byte[][] c1c2 = ByteUtils.split(input, c1Len);
byte[] c1 = c1c2[0];
byte[] c2 = c1c2[1];
// decrypt c1 ...
GF2Vector hrmVec = GF2Vector.OS2VP(n, c1);
GF2Vector[] decC1 = McElieceCCA2Primitives.decryptionPrimitive((McElieceCCA2PrivateKeyParameters)key,
hrmVec);
byte[] rBytes = decC1[0].getEncoded();
// ... and obtain error vector z
GF2Vector z = decC1[1];
// get PRNG object
DigestRandomGenerator sr0 = new DigestRandomGenerator(new SHA1Digest());
// seed PRNG with r'
sr0.addSeedMaterial(rBytes);
// generate random sequence
byte[] mBytes = new byte[c2Len];
sr0.nextBytes(mBytes);
// XOR with c2 to obtain m
for (int i = 0; i < c2Len; i++)
{
mBytes[i] ^= c2[i];
}
// compute H(r||m)
byte[] rmBytes = ByteUtils.concatenate(rBytes, mBytes);
byte[] hrm = new byte[messDigest.getDigestSize()];
messDigest.update(rmBytes, 0, rmBytes.length);
messDigest.doFinal(hrm, 0);
// compute Conv(H(r||m))
hrmVec = Conversions.encode(n, t, hrm);
// check that Conv(H(m||r)) = z
if (!hrmVec.equals(z))
{
throw new Exception("Bad Padding: invalid ciphertext");
}
// return plaintext m
return mBytes;
}
示例12: send_v2
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
public String send_v2(String recipient, long amount, String messagePayload, MosaicId mosaicId, Quantity mosaicQuantity, String fee){
// collect parameters
TimeInstant timeInstant = new SystemTimeProvider().getCurrentTime();
KeyPair senderKeyPair = new KeyPair(PrivateKey.fromHexString(this.privateKey));
Account senderAccount = new Account(senderKeyPair);
Account multisigAccount = new Account(Address.fromPublicKey(PublicKey.fromHexString(this.multisigPublicKey)));
Account recipientAccount = new Account(Address.fromEncoded(recipient));
TransferTransactionAttachment attachment = new TransferTransactionAttachment();
if(!"".equals(messagePayload.trim())){
PlainMessage message = new PlainMessage(messagePayload.getBytes());
attachment.setMessage(message);
}
if(mosaicId!=null && mosaicQuantity!=null){
attachment.addMosaic(mosaicId, mosaicQuantity);
}
if(attachment.getMessage()==null && attachment.getMosaics().size()==0){
attachment = null;
}
// create transaction
TransferTransaction transaction = new TransferTransaction(2, timeInstant, multisigAccount, recipientAccount, Amount.fromNem(amount), attachment);
TransactionFeeCalculatorAfterForkForApp feeCalculator = new TransactionFeeCalculatorAfterForkForApp();
// ignore fee or not
if(fee==null){
transaction.setFee(feeCalculator.calculateMinimumFee(transaction));
} else {
transaction.setFee(Amount.fromNem(0));
}
// create multisig transaction
MultisigTransaction multisigTransaction = new MultisigTransaction(timeInstant, senderAccount, transaction);
if(fee==null){
multisigTransaction.setFee(feeCalculator.calculateMinimumFee(multisigTransaction));
} else {
multisigTransaction.setFee(Amount.fromNem(0));
}
transaction.setDeadline(timeInstant.addHours(23));
multisigTransaction.setDeadline(timeInstant.addHours(23));
multisigTransaction.sign();
JSONObject params = new JSONObject();
final byte[] data = BinarySerializer.serializeToBytes(multisigTransaction.asNonVerifiable());
params.put("data", ByteUtils.toHexString(data));
params.put("signature", multisigTransaction.getSignature().toString());
return HttpClientUtils.post(Constants.URL_TRANSACTION_ANNOUNCE, params.toString());
}
示例13: matches
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
private boolean matches(byte[] decrypted, String hexExpected) {
// Convert byte to hex string
String hexString = ByteUtils.toHexString(decrypted);
hexExpected = hexExpected.replaceAll(" ", "");
return hexString.startsWith(hexExpected);// Cause of trailing zeroes
}
示例14: performEnDecryptionTest
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
protected final void performEnDecryptionTest(int numPassesKPG,
int numPassesEncDec, int plainTextSize,
AlgorithmParameterSpec params)
{
try
{
for (int j = 0; j < numPassesKPG; j++)
{
// generate key pair
//kpg.initialize(params);
keyPair = kpg.genKeyPair();
pubKey = keyPair.getPublic();
privKey = keyPair.getPrivate();
for (int k = 1; k <= numPassesEncDec; k++)
{
// initialize for encryption
cipher.init(Cipher.ENCRYPT_MODE, pubKey, params, sr);
// generate random message
int mLength = rand.nextInt(plainTextSize) + 1;
mBytes = new byte[mLength];
rand.nextBytes(mBytes);
// encrypt
cBytes = cipher.doFinal(mBytes);
// initialize for decryption
cipher.init(Cipher.DECRYPT_MODE, privKey, params);
// decrypt
dBytes = cipher.doFinal(cBytes);
// compare
assertEquals(
"Encryption/decryption test failed for message \""
+ ByteUtils.toHexString(mBytes)
+ "\":\n actual decrypted text: "
+ ByteUtils.toHexString(dBytes)
+ "\n expected plain text: "
+ ByteUtils.toHexString(mBytes), mBytes,
dBytes);
}
}
}
catch (Exception e)
{
e.printStackTrace();
fail(e);
}
}
示例15: performEnDecryptionTest
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入依赖的package包/类
protected final void performEnDecryptionTest(int numPassesKPG,
int numPassesEncDec, AlgorithmParameterSpec params)
{
try
{
for (int j = 0; j < numPassesKPG; j++)
{
keyPair = kpg.genKeyPair();
pubKey = keyPair.getPublic();
privKey = keyPair.getPrivate();
for (int k = 1; k <= numPassesEncDec; k++)
{
// initialize for encryption
cipher.init(Cipher.ENCRYPT_MODE, pubKey, params, sr);
// generate random message
final int plainTextSize = cipher.getBlockSize();
int mLength = rand.nextInt(plainTextSize) + 1;
mBytes = new byte[mLength];
rand.nextBytes(mBytes);
// encrypt
cBytes = cipher.doFinal(mBytes);
// initialize for decryption
cipher.init(Cipher.DECRYPT_MODE, privKey, params);
// decrypt
dBytes = cipher.doFinal(cBytes);
// compare
assertEquals("Encryption and Decryption test failed:\n"
+ " actual decrypted text: "
+ ByteUtils.toHexString(dBytes)
+ "\n expected plain text: "
+ ByteUtils.toHexString(mBytes), mBytes, dBytes);
}
}
}
catch (Exception e)
{
e.printStackTrace();
fail(e);
}
}