當前位置: 首頁>>代碼示例>>Java>>正文


Java Hex.encode方法代碼示例

本文整理匯總了Java中org.spongycastle.util.encoders.Hex.encode方法的典型用法代碼示例。如果您正苦於以下問題:Java Hex.encode方法的具體用法?Java Hex.encode怎麽用?Java Hex.encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.spongycastle.util.encoders.Hex的用法示例。


在下文中一共展示了Hex.encode方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: AttachmentServer

import org.spongycastle.util.encoders.Hex; //導入方法依賴的package包/類
public AttachmentServer(Context context, MasterSecret masterSecret, Attachment attachment)
    throws IOException
{
  try {
    this.context      = context;
    this.masterSecret = masterSecret;
    this.attachment   = attachment;
    this.socket       = new ServerSocket(0, 0, InetAddress.getByAddress(new byte[]{127, 0, 0, 1}));
    this.port         = socket.getLocalPort();
    this.auth         = new String(Hex.encode(Util.getSecretBytes(16)));

    this.socket.setSoTimeout(5000);
  } catch (UnknownHostException e) {
    throw new AssertionError(e);
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:17,代碼來源:AttachmentServer.java

示例2: testAddressStringToBytes

import org.spongycastle.util.encoders.Hex; //導入方法依賴的package包/類
@Test
public void testAddressStringToBytes() {
    // valid address
    String HexStr = "6c386a4b26f73c802f34673f7248bb118f97424a";
    byte[] expected = Hex.decode(HexStr);
    byte[] result = Utils.addressStringToBytes(HexStr);
    assertEquals(Arrays.areEqual(expected, result), true);

    // invalid address, we removed the last char so it cannot decode
    HexStr = "6c386a4b26f73c802f34673f7248bb118f97424";
    expected = null;
    result = Utils.addressStringToBytes(HexStr);
    assertEquals(expected, result);

    // invalid address, longer than 20 bytes
    HexStr = new String(Hex.encode("I am longer than 20 bytes, i promise".getBytes()));
    expected = null;
    result = Utils.addressStringToBytes(HexStr);
    assertEquals(expected, result);

    // invalid address, shorter than 20 bytes
    HexStr = new String(Hex.encode("I am short".getBytes()));
    expected = null;
    result = Utils.addressStringToBytes(HexStr);
    assertEquals(expected, result);
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:27,代碼來源:UtilsTest.java

示例3: testCheckSenderNotAuthorized

import org.spongycastle.util.encoders.Hex; //導入方法依賴的package包/類
@Test
public void testCheckSenderNotAuthorized() throws Exception {
	
	final ProviderRegister dummyProvider = new DummyProviderRegister();
	
	byte[] b = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	
	String bitmaskToString = new String(Hex.encode(b));
	
	ProviderChannel providerChannel = new ProviderChannel("providerAddress", "userAddress", bitmaskToString);
	
	dummyProvider.insertChannel(providerChannel);
	
	final UserRegister dummyUser = new DummyUserRegister();
	
	RegisterFactory dummyFactory = new RegisterFactory() {
		
		@Override
		public UserRegister getUserRegister() throws RegisterException {
			return dummyUser;
		}
		
		@Override
		public ProviderRegister getProviderRegister() throws RegisterException {
			return dummyProvider;
		}
		
		@Override
		public TransactionManager getTransactionManager() throws RegisterException {
			return null;
		}
		
	};
	
	final Connector connector = createDummyConnector();
	
	final UniquidNode node = new DummyNode();
	
	Core core = new Core(dummyFactory, connector, node) {
		
		@Override
		protected Function getFunction(FunctionRequestMessage inputMessage) {
			return null;
		}
	};
	
	final FunctionRequestMessage providerRequest = new FunctionRequestMessage();
	providerRequest.setUser("userAddress");
	providerRequest.setFunction(30);
	providerRequest.setParameters("params");
	
	try {
		
		core.checkSender(providerRequest);
		Assert.fail();
	
	} catch (Exception ex) {
		
		Assert.assertEquals("Sender not authorized!", ex.getMessage());
		
	}
	
}
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:64,代碼來源:CoreTest.java

示例4: testCheckSenderNotAuthorized1

import org.spongycastle.util.encoders.Hex; //導入方法依賴的package包/類
@Test
public void testCheckSenderNotAuthorized1() throws Exception {
	
	final ProviderRegister dummyProvider = new DummyProviderRegister();
	
	byte[] b = {1,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	
	String bitmaskToString = new String(Hex.encode(b));
	
	ProviderChannel providerChannel = new ProviderChannel("providerAddress", "userAddress", bitmaskToString);
	
	dummyProvider.insertChannel(providerChannel);
	
	final UserRegister dummyUser = new DummyUserRegister();
	
	RegisterFactory dummyFactory = new RegisterFactory() {
		
		@Override
		public UserRegister getUserRegister() throws RegisterException {
			return dummyUser;
		}
		
		@Override
		public ProviderRegister getProviderRegister() throws RegisterException {
			return dummyProvider;
		}
		
		@Override
		public TransactionManager getTransactionManager() throws RegisterException {
			return null;
		}
		
	};
	
	final Connector connector = createDummyConnector();
	
	final UniquidNode node = new DummyNode();
	
	Core core = new Core(dummyFactory, connector, node) {
		
		@Override
		protected Function getFunction(FunctionRequestMessage inputMessage) {
			return null;
		}
	};
	
	final FunctionRequestMessage providerRequest = new FunctionRequestMessage();
	providerRequest.setUser("userAddress");
	providerRequest.setFunction(31);
	providerRequest.setParameters("params");
	
	try {
		
		core.checkSender(providerRequest);
		Assert.fail();
	
	} catch (Exception ex) {
		
		Assert.assertEquals("Sender not authorized!", ex.getMessage());
		
	}
	
}
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:64,代碼來源:CoreTest.java

示例5: testCheckSenderAuthorized

import org.spongycastle.util.encoders.Hex; //導入方法依賴的package包/類
@Test
public void testCheckSenderAuthorized() throws Exception {
	
	byte[] b2 = {0, 0, 0, 0, 64};
	
	final ProviderRegister dummyProvider = new DummyProviderRegister();
	
	String bitmaskToString = new String(Hex.encode(b2));
	
	ProviderChannel providerChannel = new ProviderChannel("providerAddress", "userAddress", bitmaskToString);
	
	dummyProvider.insertChannel(providerChannel);
	
	final UserRegister dummyUser = new DummyUserRegister();
	
	RegisterFactory dummyFactory = new RegisterFactory() {
		
		@Override
		public UserRegister getUserRegister() throws RegisterException {
			return dummyUser;
		}
		
		@Override
		public ProviderRegister getProviderRegister() throws RegisterException {
			return dummyProvider;
		}
		
		@Override
		public TransactionManager getTransactionManager() throws RegisterException {
			return null;
		}
		
	};
	
	final Connector connector = createDummyConnector();
	
	final UniquidNode node = new DummyNode();
	
	Core core = new Core(dummyFactory, connector, node) {
		
		@Override
		protected Function getFunction(FunctionRequestMessage inputMessage) {
			return null;
		}
	};
	
	final FunctionRequestMessage providerRequest = new FunctionRequestMessage();
	providerRequest.setUser("userAddress");
	providerRequest.setFunction(30);
	providerRequest.setParameters("params");
	
	Assert.assertNotNull(core.checkSender(providerRequest));
	Assert.assertTrue(Arrays.equals(b2, core.checkSender(providerRequest)));
	
}
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:56,代碼來源:CoreTest.java

示例6: testCheckSenderAuthorized1

import org.spongycastle.util.encoders.Hex; //導入方法依賴的package包/類
@Test
public void testCheckSenderAuthorized1() throws Exception {
	
	final ProviderRegister dummyProvider = new DummyProviderRegister();
	
	byte[] b = {1,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	
	String bitmaskToString = new String(Hex.encode(b));
	
	ProviderChannel providerChannel = new ProviderChannel("providerAddress", "userAddress", bitmaskToString);
	
	dummyProvider.insertChannel(providerChannel);
	
	final UserRegister dummyUser = new DummyUserRegister();
	
	RegisterFactory dummyFactory = new RegisterFactory() {
		
		@Override
		public UserRegister getUserRegister() throws RegisterException {
			return dummyUser;
		}
		
		@Override
		public ProviderRegister getProviderRegister() throws RegisterException {
			return dummyProvider;
		}
		
		@Override
		public TransactionManager getTransactionManager() throws RegisterException {
			return null;
		}
		
	};
	
	final Connector connector = createDummyConnector();
	
	final UniquidNode node = new DummyNode();
	
	Core core = new Core(dummyFactory, connector, node) {
		
		@Override
		protected Function getFunction(FunctionRequestMessage inputMessage) {
			return null;
		}
	};
	
	final FunctionRequestMessage providerRequest = new FunctionRequestMessage();
	providerRequest.setUser("userAddress");
	providerRequest.setFunction(30);
	providerRequest.setParameters("params");
	
	try {
		
		Assert.assertTrue(Arrays.equals(b, core.checkSender(providerRequest)));
	
	} catch (Exception ex) {
		
		Assert.fail();
		
	}
	
}
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:63,代碼來源:CoreTest.java

示例7: testCheckSenderInvalidContractVersion

import org.spongycastle.util.encoders.Hex; //導入方法依賴的package包/類
@Test
public void testCheckSenderInvalidContractVersion() throws Exception {
	
	byte[] b2 = {2, 0, 0, 0, 64};
	
	final ProviderRegister dummyProvider = new DummyProviderRegister();
	
	String bitmaskToString = new String(Hex.encode(b2));
	
	ProviderChannel providerChannel = new ProviderChannel("providerAddress", "userAddress", bitmaskToString);
	
	dummyProvider.insertChannel(providerChannel);
	
	final UserRegister dummyUser = new DummyUserRegister();
	
	RegisterFactory dummyFactory = new RegisterFactory() {
		
		@Override
		public UserRegister getUserRegister() throws RegisterException {
			return dummyUser;
		}
		
		@Override
		public ProviderRegister getProviderRegister() throws RegisterException {
			return dummyProvider;
		}
		
		@Override
		public TransactionManager getTransactionManager() throws RegisterException {
			return null;
		}
		
	};
	
	final Connector connector = createDummyConnector();
	
	final UniquidNode node = new DummyNode();
	
	Core core = new Core(dummyFactory, connector, node) {
		
		@Override
		protected Function getFunction(FunctionRequestMessage inputMessage) {
			return null;
		}
	};
	
	final FunctionRequestMessage providerRequest = new FunctionRequestMessage();
	providerRequest.setUser("userAddress");
	providerRequest.setFunction(30);
	providerRequest.setParameters("params");
	
	try {
		
		core.checkSender(providerRequest);
		Assert.fail();
	
	} catch (Exception ex) {
		
		Assert.assertEquals("Invalid contract version!", ex.getMessage());
		
	}
	
}
 
開發者ID:uniquid,項目名稱:uidcore-java,代碼行數:64,代碼來源:CoreTest.java

示例8: encodeHex

import org.spongycastle.util.encoders.Hex; //導入方法依賴的package包/類
/**
 * Encode a string or number as hexadecimal, without '0x' prefix.
 *
 * @param str string representing hex to encode.
 *
 * @return encoded hex.
 */
static byte[] encodeHex(String str) {
  return Hex.encode(str.getBytes(Charset.defaultCharset()));
}
 
開發者ID:Aptoide,項目名稱:AppCoins-ethereumj,代碼行數:11,代碼來源:Utils.java


注:本文中的org.spongycastle.util.encoders.Hex.encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。