Created
January 20, 2017 00:21
-
-
Save dutchand/e9b6ed54d1a315b16ac7aaa0b234bd5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package com.SecurityManager.Opsec; | |
| import java.io.DataInputStream; | |
| import java.io.File; | |
| import java.io.FileInputStream; | |
| import java.io.FileNotFoundException; | |
| import java.nio.charset.Charset; | |
| import java.security.KeyFactory; | |
| import java.security.MessageDigest; | |
| import java.security.PrivateKey; | |
| import java.security.PublicKey; | |
| import java.security.spec.AlgorithmParameterSpec; | |
| import java.security.spec.KeySpec; | |
| import java.security.spec.PKCS8EncodedKeySpec; | |
| import java.security.spec.X509EncodedKeySpec; | |
| import java.util.Formatter; | |
| import java.util.Random; | |
| import javax.crypto.Cipher; | |
| import javax.crypto.SecretKey; | |
| import javax.crypto.SecretKeyFactory; | |
| import javax.crypto.spec.IvParameterSpec; | |
| import javax.crypto.spec.PBEKeySpec; | |
| import javax.crypto.spec.SecretKeySpec; | |
| import javax.xml.bind.DatatypeConverter; | |
| public class Security { | |
| //Provides Security Overview | |
| //REQUIRED KEYS | |
| File myEnPrivKey = new File(""); | |
| File appEnPubKey = new File(""); | |
| public String hashValue(String val){ | |
| String phrase=""; | |
| try{ | |
| MessageDigest crypt = MessageDigest.getInstance("SHA-1"); | |
| crypt.reset(); | |
| crypt.update((val).getBytes("UTF-8")); | |
| Formatter formatter = new Formatter(); | |
| for (byte b : crypt.digest()) | |
| { | |
| formatter.format("%02x", b); | |
| } | |
| phrase = formatter.toString(); | |
| formatter.close(); | |
| } | |
| catch (Exception e){ | |
| System.out.println(e); | |
| } | |
| return phrase; | |
| } | |
| public String getPassword(String salt){ | |
| String password=""; | |
| try{ | |
| MessageDigest crypt = MessageDigest.getInstance("SHA-1"); | |
| crypt.reset(); | |
| crypt.update((X+salt).getBytes("UTF-8")); | |
| Formatter formatter = new Formatter(); | |
| for (byte b : crypt.digest()) | |
| { | |
| formatter.format("%02x", b); | |
| } | |
| password = formatter.toString(); | |
| formatter.close(); | |
| } | |
| catch (Exception e){ | |
| System.out.println(e); | |
| } | |
| if (!password.equals("")){ | |
| //return 16 byte password | |
| return password.substring(0,16); | |
| } | |
| else { | |
| return null; | |
| } | |
| } | |
| public String generatePassword(String password, String salt){ | |
| String pass=""; | |
| //this is a hash of the server password, environment, and time | |
| try{ | |
| MessageDigest crypt = MessageDigest.getInstance("SHA-1"); | |
| crypt.reset(); | |
| crypt.update((password+salt).getBytes("UTF-8")); | |
| Formatter formatter = new Formatter(); | |
| for (byte b : crypt.digest()) | |
| { | |
| formatter.format("%02x", b); | |
| } | |
| pass = formatter.toString(); | |
| formatter.close(); | |
| } | |
| catch (Exception e){ | |
| System.out.println(e); | |
| } | |
| if (!pass.equals("")){ | |
| //return 16 byte password | |
| return pass.substring(0,16); | |
| } | |
| else { | |
| return null; | |
| } | |
| } | |
| ///////////////////////////////////////// | |
| //generate keys | |
| ///////////////////////////////////////// | |
| public String generateDataSecurityKey(){ | |
| return generateID(16); | |
| } | |
| public String generateADID(){ | |
| return generateID(20); | |
| } | |
| public String generateAAID(){ | |
| return generateID(22); | |
| } | |
| public String generateUUID(int len){ | |
| String id=""; | |
| String list="randomstring"; | |
| int count=0; | |
| while (count<len){ | |
| id=id+list.charAt((int)(Math.random()*list.length())); | |
| count++; | |
| } | |
| return id; | |
| } | |
| //........... continues | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment