ㅠㅠ hmac with sha1(hmac-sha1)을 만들려 합니다.

anaud2의 이미지

ㅠㅠ 혼자 고민하는데 자꾸 안되네요
C를 공부하고 있는데요 hmac-sha1(hmac with sha1) 으로 키값 20 byte 데이터 10byte
를 넣어서 암호문을 만들려 합니다.
KLDP에 계신분의 도움으로 hmac.h와 sha.h를 구했는데요..
이걸 어떻게 연결을 해서 사용할지 모르겠어요
ㅠㅠ 이렇게 올리는게 창피 하지만 혼자서 고민해봐도 초보라 모르겠어서 올립니다.

환경: 유닉스 C vi에디터로 작성중;

1. hmac.h, sha.h에
void SHA1(Init, Update, Final), HMAC(Init, Update, Final) 이렇게 삼수가 3개씩 있더라구요
그런데 void 형인데 만들어진 암호문은 어떻게 리턴받나요?

2. hmac.h, sha.h 이 두 헤드파일이 다 따로 저렇게 함수가 있다면 어떻게 같이 사용하죠?
Hased mac에서 해쉬알고리즘을 sha1으로 선택한다 라고 들었는데 저 헤더파일만 뜯어봐선 어떻게 서로 연동되는지 모르겠네요..

어떤 함수를 사용해야 되는지...C초보라 막막하네요..ㅠ
hmac.h와 sha.h를 첨부파일로 올려드릴게요 그리구 hmac.h와 sha.h를 구할때 같이 구한 hmac.c와 sha.c파일도 같이 올려드릴게요(별로 안중요할지도 모르지만..)
힌트라도 좀 주시기 바래요 ..ㅠ 초보라..

ps. 자바로 짯을때 내용입니다. 굳이 안보여도 되요^^;

public static byte[] hmac_sha1(byte[] Keybytes, byte[] text) //keybyte가 20바이트 입니다, text가 10바이트 입니다.
throws NoSuchAlgorithmException, InvalidKeyException
{
try {
Mac hmacSha1;
try{
hmacSha1 = Mac.getInstance("hmacSHA1");// hmacSha1에 hmacsha1알고리즘을 구현하는 mac객체 생성
} catch (NoSuchAlgorithmException nsae)
{
hmacSha1 = Mac.getInstance("HMAC-SHA-1");//에러날경우 한번더?
}
SecretKeySpec macKey = new SecretKeySpec(Keybytes,"RAW");//프로바이더에 의존하지 않는 형식에서 비밀키를
지정?
//des의 경우 키가 8바이트일지 어떨지 판정하지 않는다.
//keybytes(비밀키의원본),"raw"비밀키알고리즘 이름 RAW?

hmacSha1.init(macKey);//init은 키값을 이용해서 Mac오브젝트 초기화(여기선 mackey)

return hmacSha1.doFinal(text);// mac오브젝트 종료?
}catch(GeneralSecurityException gse)
{
throw new UndeclaredThrowableException(gse);
}
}

File attachments: 
첨부파일 크기
Package icon hmacsha1.zip8.86 KB
mithrandir의 이미지

HMAC_Init_ex(키 설정) -> update(문자열 집어넣기) -> Final(결과값 받기)

openssl 매뉴얼좀 보시구요. Call by reference에 대해서도 공부해보세요.

언제나 삽질 - http://tisphie.net/typo/
프로그래밍 언어 개발 - http://langdev.net

언제나 삽질 - http://tisphie.net/typo/
프로그래밍 언어 개발 - http://langdev.net

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.