This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getTOTPCode(String secretKey) { | |
String normalizedBase32Key = secretKey.replace(" ", "").toUpperCase(); | |
Base32 base32 = new Base32(); | |
byte[] bytes = base32.decode(normalizedBase32Key); | |
String hexKey = Hex.encodeHexString(bytes); | |
long time = (System.currentTimeMillis() / 1000) / 30; | |
String hexTime = Long.toHexString(time); | |
return TOTP.generateTOTP(hexKey, hexTime, "6"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getRandomSecretKey() { | |
SecureRandom random = new SecureRandom(); | |
byte[] bytes = new byte[20]; | |
random.nextBytes(bytes); | |
Base32 base32 = new Base32(); | |
String secretKey = base32.encodeToString(bytes); | |
// make the secret key more human-readable by lower-casing and | |
// inserting spaces between each group of 4 characters | |
return secretKey.toLowerCase().replaceAll("(.{4})(?=.{4})", "$1 "); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>commons-codec</groupId> | |
<artifactId>commons-codec</artifactId> | |
<version>1.10</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load data infile '/tmp/file.csv' | |
into table my_table | |
fields terminated by ',' | |
optionally enclosed by '"' | |
escaped by '"' | |
lines terminated by '\n' | |
ignore 1 lines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
mysql databasename -h hostname -u username -p -B -e "select * from mytable;" > /tmp/myreport.tsv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
keytool -genkey -validity 365 -alias "youralias" -keyalg "RSA" -keystore .keystore -keypass "yourkeypass" -storepass "yourstorepass" -dname "CN=localhost, OU=, O=, L=, S=, C=" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
openssl req -new -newkey rsa:2048 -nodes -days 365 -x509 -subj "/C=/ST=/L=/O=/CN=localhost" -keyout privkey.pem -out cacert.pem |
NewerOlder