천객만래 [千客萬來] (It has an interminable succession of visitors)





주민번호검증하기2

- charCodeAt() : 해당인덱스에 해당하는 문자의 ascii코드값을 반환합니다.
- substring(x, y) : 인덱스[x]값에서부터 인덱스[y]값이전까지의 문자열을 반환합니다.



* 주민등록번호의 공식
주민등록번호의 13자리로 이루어져 있습니다.
- 처리1 : [첫번째번호*2] + [두번째번호*3] + [세번째번호*4] + [네번째번호*5] + [다섯번째번호*6]
    + [여섯번째번호*7] + [일곱번째번호*8] + [여덟번째번호*9] + [아홉번째번호*2] + [열번째번호*3]
    + [열한번째번호*4] + [열두번째번호*5]의 합
- 처리2 : [처리1값] % 11
- 처리3 : [[처리1값] - [처리2값]] + 11 - [처리1값]
- 처리4 : [처리3값] % 10
- 처리5 : [처리3값] - [[처리3값] - [처리4값]]





----------------------------------------------------------------------------------------



<html>
<script language="JavaScript">
<!--



function name_check(ch_name) {  /* 이름체크 */
var len = ch_name.length;



if (len < 2) {  /* 이름은 두자이상 */
  alert("이름이 잘못되었습니다.");
  frm1.myname.focus();
  return false;
}



for (i=0; i<len; i++) {
  var mycode = ch_name.charCodeAt(i);  /* 해당인덱스 문자의 ascii코드값 */



  if (mycode < 128) {  /* 128이상은 한글 */
   alert("한글 이름으로 입력하세요");
   frm1.myname.focus();
   return false;
  }
}


return true;
}



function jumin_check(ssn_jumin) {  /* 주민번호 확인 */
var ssn_num = new Array();
var ssn_jumin1 = new String(ssn_jumin);  /* 입력된 숫자의 문자열화 */



if (ssn_jumin1.length != 13) {
  alert("주민등록번호 13자리인지를 확인하여 주십시오");
  frm1.jumin1.focus();
  return false;
}



for (var i=0; i<=12; i++)
  ssn_num[i] = ssn_jumin1.substring(i, i+1);  /* [i]에서 [i+1]까지 문자를 추출 */



/* 주민등록번호 공식의 시작 */
var sum = 2*ssn_num[0] + 3*ssn_num[1] + 4*ssn_num[2] + 5*ssn_num[3];
sum += 6*ssn_num[4] + 7*ssn_num[5] + 8*ssn_num[6] + 9*ssn_num[7];
sum += 2*ssn_num[8] + 3*ssn_num[9] + 4*ssn_num[10] + 5*ssn_num[11];

var r1 = sum % 11;
var temp = (sum-r1) + 11 - sum;
var r2 = temp % 10;
var temp1 = temp - (temp-r2);
/* 주민등록번호 공식의 끝 */



if (ssn_num[12] != temp1) {  /* 해당 주민번호를 검증 */
  alert("올바른 주민등록번호가 아닙니다.");
  return false;
}



return true;
}



function frm_check() {  /* 각 함수를 호출/확인한다. */
var jumin_name = frm1.myname.value;
var jumin_num = frm1.jumin1.value + frm1.jumin2.value;



if (name_check(jumin_name) == false)
  return false;

if (jumin_check(jumin_num) == false)
  return false;

}



-->
</script>



<body onload="frm1.myname.focus();">
<table border=1 cellpadding=5 cellspacing=2 bordercolor="#bbddaa">
<form name="frm1" onsubmit="return frm_check()">



<tr>
<td bgcolor="#aacc99" align="center">이 름</td>
<td bgcolor="#cceebb"><input type="text" name="myname" maxlength=10 size=10></td>
</tr>
<tr>
<td bgcolor="#aacc99">주민등록번호</td>
<td bgcolor="#cceebb">
  <input type="text" name="jumin1" maxlength=6 size=6>-
  <input type="text" name="jumin2" maxlength=7 size=7>
</td>
</tr>
<tr>
<td colspan=2 align="center">
  <input type="submit" value=" 확인 ">
</td>
</tr>



</form>
</table>
</body>
</html>


출처: 인터넷

Posted by SB패밀리







사업자등록번호 검증하기

- isNuN() : 해당값이 문자인지 숫자인지 파악합니다. 숫자가 아니면 true값을 반환합니다.
- parseInt(변수, 한계값) : 해당값의 소수부분을 버림합니다.



* 전기신호의 0, 1이 off, on를 의미하듯이 javascript의 0은 false, 그 외 다른 수는 true를 의미합니다.



* 사업자 등록번호 공식
사업자번호는 총 10자리로 이루어져 있습니다.
처리1 ; 아홉번째 번호 *5
처리2 : [처리1] /10
처리3 : [처리1] %10 (나눈 목의 나머지값)
처리4 : (첫번째번호*1) + (두번째번호*3) + (세번째번호*7) + (네번째번호*1) + (다섯번째번호*3)
   + (여섯번째번호*7) + (일곱번째번호*1) + (여덟번째번호*3) + (열번째번호*1) + [처리2] + [처리3]
처리5 : [처리4]에서 구해진 결과값을 10으로 나누어 나머지가 0이면 사업자 등록번호가 맞습니다.





----------------------------------------------------------------------------------------



<html>
<script language="JavaScript">
<!--



function sa_check() {

var num = (frm1.num1.value + frm1.num2.value + frm1.num3.value);



if (num.length < 1) {  /* 아무것도 입력하지 않으면 에러 */
  alert("사업자 번호를 입력하세요.");
  frm1.num1.focus();
  return false;
}



if (isNaN(num)) {  /* 숫자가 아니면 에러 */
  alert("숫자만 입력하세요");
  frm1.num1.focus();
  return false;
}



var w1, w2, w3, wt;  /* 사업자번호 공식의 시작↓ */



w1 = num.charAt(8) *5;
w2 = parseInt((w1/10), 10);  /* 소수부분을 제거 */
w3 = w1 %10;



wt = num.charAt(0) *1 + num.charAt(1) *3 + num.charAt(2) *7;
wt += num.charAt(3) *1 + num.charAt(4) *3 + num.charAt(5) *7;
wt += num.charAt(6) *1 + num.charAt(7) *3 + num.charAt(9) *1;
wt += (w2 + w3);



if (!(wt %10)) {  /* 0은 false, 이외 숫자는 true입니다. !는 not을 의미합니다. */
  return true;
}
else {
  alert("규칙에 맞지 않는 사업자 등록번호입니다.");
  frm1.num1.focus();
  return false;
}

return true;
}



-->
</script>



<body onload="frm1.myname.focus()">
<form name="frm1" onsubmit="return sa_check()">
<table border=1 bordercolor="#cc9999" cellpadding=3 cellspacing=3>



<tr>
<td width=120 bgcolor="#ccaaaa" align="center">대표자</td>
<td width=150 bgcolor="#eeccbb" align="center">
  <input type="text" name="myname" size=10 maxlength=10>
</td>
</tr>
<tr>
<td bgcolor="#ccaaaa" align="center">사업자 등록번호</td>
<td bgcolor="#eeccbb" align="center">
  <input type="text" name="num1" size=3 maxlength=3>-
  <input type="text" name="num2" size=2 maxlength=2>-
  <input type="text" name="num3" size=5 maxlength=5>
</td>
</tr>
<tr>
<td colspan=2 align="center">
  <input type="submit" value=" 확인 ">
</td>
</tr>



</table>
</form>
</body>
</html>

Posted by SB패밀리

MSDN에서 찾았습니다.

Example C Program: Verifying the Signature of a PE File
http://msdn2.microsoft.com/en-us/library/aa382384(VS.85).aspx

//-------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// Example of verifying the embedded signature of a PE file by using 
// the WinVerifyTrust function.

#define _UNICODE 1
#define UNICODE 1

#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <Softpub.h>
#include <wincrypt.h>
#include <wintrust.h>

// Link with the Wintrust.lib file.
#pragma comment (lib, "wintrust")

BOOL VerifyEmbeddedSignature(LPCWSTR pwszSourceFile)
{
    LONG lStatus;
    DWORD dwLastError;

    // Initialize the WINTRUST_FILE_INFO structure.

    WINTRUST_FILE_INFO FileData;
    memset(&FileData, 0, sizeof(FileData));
    FileData.cbStruct = sizeof(WINTRUST_FILE_INFO);
    FileData.pcwszFilePath = pwszSourceFile;
    FileData.hFile = NULL;
    FileData.pgKnownSubject = NULL;

    /*
    WVTPolicyGUID specifies the policy to apply on the file
    WINTRUST_ACTION_GENERIC_VERIFY_V2 policy checks:
    
    1) The certificate used to sign the file chains up to a root 
    certificate located in the trusted root certificate store. This 
    implies that the identity of the publisher has been verified by 
    a certification authority.
    
    2) In cases where user interface is displayed (which this example
    does not do), WinVerifyTrust will check for whether the  
    end entity certificate is stored in the trusted publisher store,  
    implying that the user trusts content from this publisher.
    
    3) The end entity certificate has sufficient permission to sign 
    code, as indicated by the presence of a code signing EKU or no 
    EKU.
    */

    GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
    WINTRUST_DATA WinTrustData;

    // Initialize the WinVerifyTrust input data structure.

    // Default all fields to 0.
    memset(&WinTrustData, 0, sizeof(WinTrustData));

    WinTrustData.cbStruct = sizeof(WinTrustData);
    
    // Use default code signing EKU.
    WinTrustData.pPolicyCallbackData = NULL;

    // No data to pass to SIP.
    WinTrustData.pSIPClientData = NULL;

    // Disable WVT UI.
    WinTrustData.dwUIChoice = WTD_UI_NONE;

    // No revocation checking.
    WinTrustData.fdwRevocationChecks = WTD_REVOKE_NONE; 

    // Verify an embedded signature on a file.
    WinTrustData.dwUnionChoice = WTD_CHOICE_FILE;

    // Default verification.
    WinTrustData.dwStateAction = 0;

    // Not applicable for default verification of embedded signature.
    WinTrustData.hWVTStateData = NULL;

    // Not used.
    WinTrustData.pwszURLReference = NULL;

    // Default.
    WinTrustData.dwProvFlags = WTD_SAFER_FLAG;

    // This is not applicable if there is no UI because it changes 
    // the UI to accommodate running applications instead of 
    // installing applications.
    WinTrustData.dwUIContext = 0;

    // Set pFile.
    WinTrustData.pFile = &FileData;

    // WinVerifyTrust verifies signatures as specified by the GUID 
    // and Wintrust_Data.
    lStatus = WinVerifyTrust(
        NULL,
        &WVTPolicyGUID,
        &WinTrustData);

    switch (lStatus) 
    {
        case ERROR_SUCCESS:
            /*
            Signed file:
                - Hash that represents the subject is trusted.

                - Trusted publisher without any verification errors.

                - UI was disabled in dwUIChoice. No publisher or 
                    time stamp chain errors.

                - UI was enabled in dwUIChoice and the user clicked 
                    "Yes" when asked to install and run the signed 
                    subject.
            */
            wprintf_s(L"The file \"%s\" is signed and the signature "
                L"was verified.\n",
                pwszSourceFile);
            break;
        
        case TRUST_E_NOSIGNATURE:
            // The file was not signed or had a signature 
            // that was not valid.

            // Get the reason for no signature.
            dwLastError = GetLastError();
            if (TRUST_E_NOSIGNATURE == dwLastError ||
                    TRUST_E_SUBJECT_FORM_UNKNOWN == dwLastError ||
                    TRUST_E_PROVIDER_UNKNOWN == dwLastError) 
            {
                // The file was not signed.
                wprintf_s(L"The file \"%s\" is not signed.\n",
                    pwszSourceFile);
            } 
            else 
            {
                // The signature was not valid or there was an error 
                // opening the file.
                wprintf_s(L"An unknown error occurred trying to "
                    L"verify the signature of the \"%s\" file.\n",
                    pwszSourceFile);
            }

            break;

        case TRUST_E_EXPLICIT_DISTRUST:
            // The hash that represents the subject or the publisher 
            // is not allowed by the admin or user.
            wprintf_s(L"The signature is present, but specifically "
                L"disallowed.\n");
            break;

        case TRUST_E_SUBJECT_NOT_TRUSTED:
            // The user clicked "No" when asked to install and run.
            wprintf_s(L"The signature is present, but not "
                L"trusted.\n");
            break;

        case CRYPT_E_SECURITY_SETTINGS:
            /*
            The hash that represents the subject or the publisher 
            was not explicitly trusted by the admin and the 
            admin policy has disabled user trust. No signature, 
            publisher or time stamp errors.
            */
            wprintf_s(L"CRYPT_E_SECURITY_SETTINGS - The hash "
                L"representing the subject or the publisher wasn't "
                L"explicitly trusted by the admin and admin policy "
                L"has disabled user trust. No signature, publisher "
                L"or timestamp errors.\n");
            break;

        default:
            // The UI was disabled in dwUIChoice or the admin policy 
            // has disabled user trust. lStatus contains the 
            // publisher or time stamp chain error.
            wprintf_s(L"Error is: 0x%x.\n",
                lStatus);
            break;
    }

    return true;
}

int _tmain(int argc, _TCHAR* argv[])
{
    if(argc > 1)
    {
        VerifyEmbeddedSignature(argv[1]);
    }

    return 0;
}

파일이 사인되어 있다면 WinVerifyTrust결과로 ERROR_SUCCESS가 리턴 됩니다.
Posted by SB패밀리