changeset 1517:04615093b19d

use digest_message
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 09 Jun 2020 12:36:16 -0600
parents 70a55f49b98e
children f989778ca9e1
files src/luan/host/Util.luan
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/host/Util.luan	Mon Jun 08 21:54:31 2020 -0600
+++ b/src/luan/host/Util.luan	Tue Jun 09 12:36:16 2020 -0600
@@ -7,18 +7,17 @@
 local String = require "luan:String.luan"
 local lower = String.lower or error()
 local format = String.format or error()
+local to_binary = String.to_binary or error()
 local Binary = require "luan:Binary.luan"
 local bytes = Binary.byte or error()
 local base64_encode = Binary.base64_encode or error()
+local digest_message = Binary.digest_message or error()
 local Hosted = require "luan:host/Hosted.luan"
 local Sql = require "luan:sql/Sql.luan"
 local database = Sql.database or error()
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "Util"
 
-require "java"
-local MessageDigest = require "java:java.security.MessageDigest"
-
 
 local Util = {}
 
@@ -28,7 +27,7 @@
 end
 
 local function basic_authentication(dir,password)
-	local sha1 = MessageDigest.getInstance("SHA1").digest(password.getBytes())
+	local sha1 = digest_message("SHA1",to_binary(password))
 	local encoded = base64_encode(sha1)
 	local file = Io.schemes.file(dir.."/password.nginx")
 	file.delete()
@@ -37,7 +36,7 @@
 
 local function digest_authentication(dir,password)
 	local s = "admin:Restricted:"..password
-	local md5 = MessageDigest.getInstance("MD5").digest(s.getBytes())
+	local md5 = digest_message("MD5",to_binary(s))
 	md5 = {bytes(md5,1,#md5)}
 	local encoded = ""
 	for _, n in ipairs(md5) do