当前位置: 首页>>代码示例>>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;未经允许,请勿转载。