Java Code Examples for org.spongycastle.util.encoders.Hex#encode()
The following examples show how to use
org.spongycastle.util.encoders.Hex#encode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UtilsTest.java From ethereumj with MIT License | 6 votes |
@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); }
Example 2
Source File: MediaHasher.java From CameraV with GNU General Public License v3.0 | 6 votes |
public static String hash (InputStream is, String hashFunction) throws IOException, NoSuchAlgorithmException { MessageDigest digester; digester = MessageDigest.getInstance(hashFunction); //MD5 or SHA-1 int BYTE_READ_SIZE = 1024*64; // 64k chunks byte[] bytes = new byte[BYTE_READ_SIZE]; int byteCount; while ((byteCount = is.read(bytes)) > 0) { digester.update(bytes, 0, byteCount); } byte[] messageDigest = digester.digest(); return new String(Hex.encode(messageDigest), Charset.forName("UTF-8")); }
Example 3
Source File: AttachmentServer.java From bcm-android with GNU General Public License v3.0 | 5 votes |
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(EncryptUtils.getSecretBytes(16))); this.socket.setSoTimeout(5000); } catch (UnknownHostException e) { throw new AssertionError(e); } }
Example 4
Source File: EncryptUtil.java From PocketEOS-Android with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets encrypt string. *加密 * @param content the content * @param password the password * @return the encrypt string * @throws NoSuchAlgorithmException the no such algorithm exception * @throws InvalidKeySpecException the invalid key spec exception */ public static String getEncryptString(String content, String password) throws NoSuchAlgorithmException, InvalidKeySpecException { String salt = getRandomString(32);//盐 char[] chars = password.toCharArray();//加密密码明文 byte[] encryPassword = pbkdf2(chars, salt.getBytes(), 1000, 32); // 加密 byte[] enc = encrypt(content.getBytes(), encryPassword); return salt + new String(Hex.encode(enc)); }
Example 5
Source File: ExtendedPublicKey.java From dapp-wallet-demo with Apache License 2.0 | 4 votes |
public String getPublicKey(){ return new String(Hex.encode(getKey())); }
Example 6
Source File: ExtendedPrivateKey.java From dapp-wallet-demo with Apache License 2.0 | 4 votes |
public String getPrivateKey(){ return new String(Hex.encode(getKey())); }
Example 7
Source File: PgpUtils.java From proofmode with GNU General Public License v3.0 | 4 votes |
public String getPublicKeyFingerprint () { PGPPublicKey key = pkr.getPublicKey(); String fullKey = new String(Hex.encode(key.getFingerprint())); return fullKey.substring(fullKey.length()-16); }
Example 8
Source File: KeyUtility.java From CameraV with GNU General Public License v3.0 | 4 votes |
public static String getFingerprintFromKey(byte[] keyblock) throws IOException, PGPException { PGPPublicKey key = extractPublicKeyFromBytes(keyblock); return new String(Hex.encode(key.getFingerprint())); }
Example 9
Source File: MediaHasher.java From CameraV with GNU General Public License v3.0 | 3 votes |
public static String getJpegHash(InputStream is) throws NoSuchAlgorithmException, IOException { JPEGDecoder decoder = new JPEGDecoder(is); decoder.decodeHeader(); int width = decoder.getImageWidth(); //int height = decoder.getImageHeight(); decoder.startDecode(); int stride = width*4; //4 bytes per pixel RGBA MessageDigest digester = MessageDigest.getInstance("SHA-1"); // System.out.println("Stride: " + stride); for(int h=0; h<decoder.getNumMCURows(); h++) { ByteBuffer bb = ByteBuffer.allocate(stride * decoder.getMCURowHeight()); // System.out.println("handling row: " + h); decoder.decodeRGB(bb, stride, 1); digester.update(bb.array()); } byte[] messageDigest = digester.digest(); return new String(Hex.encode(messageDigest), Charset.forName("UTF-8")); }
Example 10
Source File: MediaHasher.java From CameraV with GNU General Public License v3.0 | 3 votes |
public static String getJpegHash(byte[] jpegBytes) throws NoSuchAlgorithmException, IOException { JPEGDecoder decoder = new JPEGDecoder(new ByteArrayInputStream(jpegBytes)); decoder.decodeHeader(); int width = decoder.getImageWidth(); //int height = decoder.getImageHeight(); decoder.startDecode(); int stride = width*4; //4 bytes per pixel RGBA MessageDigest digester = MessageDigest.getInstance("SHA-1"); // System.out.println("Stride: " + stride); for(int h=0; h<decoder.getNumMCURows(); h++) { ByteBuffer bb = ByteBuffer.allocate(stride * decoder.getMCURowHeight()); // System.out.println("handling row: " + h); decoder.decodeRGB(bb, stride, 1); digester.update(bb.array()); } byte[] messageDigest = digester.digest(); return new String(Hex.encode(messageDigest), Charset.forName("UTF-8")); }
Example 11
Source File: MediaHasher.java From CameraV with GNU General Public License v3.0 | 3 votes |
public static String getBitmapHash(Bitmap bitmap) throws NoSuchAlgorithmException, IOException { MessageDigest digester = MessageDigest.getInstance("SHA-1"); for(int h=0; h<bitmap.getHeight(); h++) { int[] row = new int[bitmap.getWidth()]; bitmap.getPixels(row, 0, row.length, 0, h, row.length, 1); //System.out.println("row " + h + "=" + row[0]); byte[] rowBytes = new byte[row.length]; for(int b=0; b<row.length; b++) { int p = row[b]; rowBytes[b] = (byte) p; int R = (p >> 16) & 0xff; int G = (p >> 8) & 0xff; int B = p & 0xff; if (b == 0) System.out.println("row " + h + ": " + R +"," + G + "," + B); } digester.update(rowBytes); //byte[] messageDigest = digester.digest(); //String lineHash = new String(Hex.encode(messageDigest), Charset.forName("UTF-8")); //System.out.println("line " + h + "=" + lineHash); rowBytes = null; row = null; } byte[] messageDigest = digester.digest(); return new String(Hex.encode(messageDigest), Charset.forName("UTF-8")); }