mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 11:00:38 +00:00
Moving files to packages
This commit is contained in:
parent
0744dcccf1
commit
d91e20e1f8
14 changed files with 0 additions and 0 deletions
2135
src/main/java/org/asamk/signal/util/Base64.java
Normal file
2135
src/main/java/org/asamk/signal/util/Base64.java
Normal file
File diff suppressed because it is too large
Load diff
31
src/main/java/org/asamk/signal/util/Hex.java
Normal file
31
src/main/java/org/asamk/signal/util/Hex.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package org.asamk.signal;
|
||||
|
||||
public class Hex {
|
||||
|
||||
private final static char[] HEX_DIGITS = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
||||
};
|
||||
|
||||
public static String toStringCondensed(byte[] bytes) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
appendHexChar(buf, bytes[i]);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static void appendHexChar(StringBuffer buf, int b) {
|
||||
buf.append(HEX_DIGITS[(b >> 4) & 0xf]);
|
||||
buf.append(HEX_DIGITS[b & 0xf]);
|
||||
buf.append(" ");
|
||||
}
|
||||
|
||||
public static byte[] toByteArray(String s) {
|
||||
int len = s.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
31
src/main/java/org/asamk/signal/util/Util.java
Normal file
31
src/main/java/org/asamk/signal/util/Util.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package org.asamk.signal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
class Util {
|
||||
public static String getSecret(int size) {
|
||||
byte[] secret = getSecretBytes(size);
|
||||
return Base64.encodeBytes(secret);
|
||||
}
|
||||
|
||||
public static byte[] getSecretBytes(int size) {
|
||||
byte[] secret = new byte[size];
|
||||
getSecureRandom().nextBytes(secret);
|
||||
return secret;
|
||||
}
|
||||
|
||||
private static SecureRandom getSecureRandom() {
|
||||
try {
|
||||
return SecureRandom.getInstance("SHA1PRNG");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static File createTempFile() throws IOException {
|
||||
return File.createTempFile("signal_tmp_", ".tmp");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue