{% extends 'base.html' %} {% block content %}

포렌식


해시란?
임의의 길이를 가진 데이터를 고정된 길이의 값으로 변환하는 함수나 결과를 말함. 이때 결과값을 해시값이라고 부른다.

실습

변환결과:
{{convert_text}} : {{convert_result}}
def calculate_hash_string(text, algorithm="md5"):
  """문자열 해시 계산"""
  h = hashlib.new(algorithm)
  h.update(text.encode("utf-8"))
  return h.hexdigest()
def calculate_hash_file(file, algorithm="md5"):
  """파일 해시 계산 (chunk 단위로)"""
  h = hashlib.new(algorithm)
  while chunk := file.read(8192):
   h.update(chunk)
  file.seek(0) # 파일 포인터 초기화 (다시 사용 가능하도록)
  return h.hexdigest()

if option == "string":
  input_text = request.form.get("inputText", "")
  if input_text:
   result = calculate_hash_string(input_text)
   return render_template('forensic/index.html',convert_text=input_text,convert_result=result,active_tab=active_tab)
elif option == "file":
   uploaded_file = request.files.get("inputFile")
   if uploaded_file and uploaded_file.filename != "":
   result = calculate_hash_file(uploaded_file)
   return render_template('forensic/index.html',convert_text=uploaded_file.filename,convert_result=result,active_tab=active_tab)
{% endblock %}