Returns
@param encryptedToken
@return Pair<Username, DigestedPassword>
@throws RuntimeException - "Malformed Token", "Token Expired" throws exception
430536
public Pair<String, String> decryptResetToken(String encryptedToken) throws RuntimeException {
       // USER_ID-sep-DIGESTED_HASH-sep-System.currentTimeMillis
       String decriptedMessage = tokenEncryptor.decrypt(encryptedToken);
       String[] decriptArray = decriptedMessage.split(SEPARATOR);

       if (decriptArray.length != 3) {
           throw new RuntimeException("Malformed Token");
       }

       if (!isTokenUnexpired(decriptArray[2])) {
           throw new RuntimeException("Token Expired");
       }

       String username = decriptArray[0];
       String digestedPassword =  decriptArray[1];

       return new Pair<String, String>(username, digestedPassword);
   }
290317
public String auth_getSession(String authToken)
    throws FacebookException, IOException {
    if (null != this._sessionKey) {
      return this._sessionKey;
    }
    JSONObject d = (JSONObject) this.callMethod(FacebookMethod.AUTH_GET_SESSION, 
                                                new Pair<String, CharSequence>("auth_token", authToken.toString()));
    this._sessionKey = (String) d.get("session_key");
    Object uid = d.get("uid");
    try {
      this._userId = ((Long) uid).intValue();
    } catch (ClassCastException cce) {
      this._userId = Integer.parseInt((String) uid);
    } 
    if (this.isDesktop()) {
      this._sessionSecret = (String) d.get("secret");
    }
    return this._sessionKey;
  }
5747
private static String extractPassword(String password, ClientAuthScheme scheme) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance(ClientAuthScheme.getDigestScheme(scheme));
        } catch (final NoSuchAlgorithmException e) {
            hostLog.l7dlog(Level.FATAL, LogKeys.compiler_VoltCompiler_NoSuchAlgorithm.name(), e);
            System.exit(-1);
        }
        final byte passwordHash[] = md.digest(password.getBytes(Charsets.UTF_8));
        return Encoder.hexEncode(passwordHash);
    }
1116931
@Override
    public OAuthToken get(String envKey) {
        if (!oAuthToken.containsKey(envKey)) return null;
        
        return oAuthToken.get(envKey);
    }
809361
private static String createSecureRandom() {
        try {
            final String no = "" + SECURE_RANDOM.nextInt();
            final MessageDigest md = MessageDigest.getInstance("SHA-1");
            final byte[] digest = md.digest(no.getBytes());
            return encodeBase64(digest);
        } catch (final NoSuchAlgorithmException ex) {
            throw new RuntimeException(ex);
        }
    }
1338832
public static String computeSignature(UserDetails userDetails, long expires) {
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("No " + MESSAGE_DIGEST_ALGORITHM + " algorithm available!", e);
        }

        String signature = userDetails.getUsername() + TOKEN_SEPARATOR + expires + TOKEN_SEPARATOR + userDetails.getPassword() + TOKEN_SEPARATOR + TokenUtils.MAGIC_KEY;

        return new String(Hex.encode(digest.digest(signature.getBytes(Charsets.UTF_8))));
    }
417508
public static Token parseToken(byte[] secret, String token) {
        Token tk = new Token();
        if (S.blank(token)) return tk;
        String s = "";
        try {
            s = Crypto.decryptAES(token, secret);
        } catch (Exception e) {
            return tk;
        }
        String[] sa = s.split("\\|");
        if (sa.length < 2) return tk;
        tk.id = sa[0];
        try {
            tk.due = Long.parseLong(sa[1]);
            if (tk.expired()) {
                return tk;
            }
        } catch (Exception e) {
            tk.due = $.ms() - 1000 * 60 * 60 * 24;
            return tk;
        }
        if (sa.length > 2) {
            sa = Arrays.copyOfRange(sa, 2, sa.length);
            tk.payload.addAll(C.listOf(sa));
        }
        return tk;
    }
982329
public ManagedObject get(Token storedToken)
                    throws ObjectManagerException {
        final String methodName = "get";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        methodName,
                        new Object[] { storedToken });

        byte[] managedObjectBytes = null;

        try {
            String storedObjectFileName = storeDirectoryName + java.io.File.separator + storedToken.storedObjectIdentifier;

            if (Tracing.isAnyTracingEnabled() && trace.isDebugEnabled())
                trace.debug(this,
                            cclass,
                            methodName,
                            new Object[] { storedObjectFileName });

            java.io.RandomAccessFile storeFile = new java.io.RandomAccessFile(storedObjectFileName,
                                                                              "r");
            long fileLength = storeFile.length();
            managedObjectBytes = new byte[(int) fileLength];
            storeFile.readFully(managedObjectBytes);
            storeFile.close();

        } catch (java.io.FileNotFoundException exception) {
            // No FFDC Code Needed.
            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           methodName,
                           exception);
            return null;

        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, methodName, exception, "1:286:1.17");

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           methodName,
                           exception);
            throw new TemporaryIOException(this,
                                           exception);
        } // catch IOException.

        // Recover the ManagedObject from its serialized bytes.
        ManagedObject objectFromStore = ManagedObject.restoreFromSerializedBytes(managedObjectBytes,
                                                                                 objectManagerState);
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       methodName,
                       new Object[] { objectFromStore });
        return objectFromStore;
    }
1329637
public static byte[] getHashedPassword(ClientAuthScheme scheme, String password) {
        if (password == null) {
            return null;
        }

        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance(ClientAuthScheme.getDigestScheme(scheme));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            System.exit(-1);
        }
        byte hashedPassword[] = null;
        hashedPassword = md.digest(password.getBytes(Constants.UTF8ENCODING));
        return hashedPassword;
    }
1029308
public static byte[] keyGenPrivate(byte[] randomBytes) throws NoSuchAlgorithmException, DigestException {

        if (randomBytes.length < 32) {
            throw new RuntimeException("Random bytes too small");
        }

        // Hashing Random Bytes instead of using random bytes directly
        // Just in case as reference ed255519 implementation do same
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        digest.digest(randomBytes, 0, randomBytes.length);
        byte[] privateKey = digest.digest();

        // Performing bit's flipping
        privateKey[0] &= 248;
        privateKey[31] &= 127;
        privateKey[31] |= 64;

        return privateKey;
    }
102146
@Override
    public String getToken() throws TokenManagerException {
        if (hasTokenExpired()) {
            synchronized (this) {
                if (hasTokenExpired()) {
                    try {
                        final IAMToken iamToken = invokeTokenApi();
                        expiresAt = (long) (TimeUnit.SECONDS.toNanos(
                                iamToken.expires_in) * tokenExpiryThreshold)
                                + System.nanoTime();
                        token = iamToken.access_token;
                    } catch (final IAMTokenException e) {
                        throw new TokenManagerException("Failed getting Token.",
                                e);
                    }

                }
            }
        }
        return token;
    }
1062550
protected function getToken($type, $tokenRequired = true)
    {
        $token = $this->tokenStorage->getToken();

        if ($tokenRequired && null === $token) {
            throw new RuntimeException(sprintf('The current %s cannot be added in security token because the security token is empty', $type));
        }

        return $token;
    }
1099638
private String encryptPassword(String password)
            throws AuthenticationException {
        byte[] passwordBytes = password.getBytes();

        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(passwordBytes);

            byte messageDigest[] = algorithm.digest();
            BigInteger number = new BigInteger(1, messageDigest);

            password = number.toString(16);
            if (password.length() == 31) {
                password = "0" + password;
            }
        } catch (Exception e) {
            throw new AuthenticationException(
                    "Internal password encryption failure: " + e.getMessage());
        }
        return password;
    }
977315
protected String encryptResolvedUsername(final Principal principal, final Service service, final RegisteredService registeredService, final String username) {
        val applicationContext = ApplicationContextProvider.getApplicationContext();
        val cipher = applicationContext.getBean("registeredServiceCipherExecutor", RegisteredServiceCipherExecutor.class);
        return cipher.encode(username, Optional.of(registeredService));
    }
68566
public static String digestAuthHeader(String username, String password, String realm, String noncekey, String method, String uri, String opaque, String algorithm, TestContext context) {
        return new DigestAuthHeaderFunction().execute(Arrays.asList(username, password, realm, noncekey, method, uri, opaque, algorithm), context);
    }
577662
function verifyToken(token) {
    var decodedToken = jwt.decode(token)
    return userdb.users.filter(user => user.name == decodedToken).length > 0;
}
141511
private String hash(String token) {
        // perform the hashing of the token key
        String hashedToken = null;

        if (hash_type.equalsIgnoreCase("SHA")) {
            hashedToken = Util.sha(token);
        } else {
            hashedToken = Util.md5(token);
        }

        if (hashedToken == null) {
            // failed to hash - sending the token in clear text
            // Note that this may be considered a security vulnerabiltiy if clear text passwords are forbidden.

            log.warn("Failed to hash token - sending in clear text");
            return token;
        }
        return hashedToken;
    }