아래 뜨는 Download 나 PC App Store는 모두의 프린터와 상관없는 광고입니다!!
특히 PC App Store는 악성 소프트웨어이니 절대 클릭하지 마세요!!
모두의 프린터는 어떠한 경우에도 본인인증, 회원가입, 카드결제를 요구하지 않습니다.
다운로드를 유도하는 애드센스 광고를 피로곰이 배포하는 프로그램들의 다운로드 링크로 착각하지 않도록 주의하시기 바랍니다. 피로곰이 배포하는 모든 프로그램은 본인인증, 회원가입, 이용료 결제 없이 무료로 사용가능합니다.
많이 찾는 글들...
  1. PC App Store 제거 방법
  2. Ghostscript/GhostPCL 설치 안내
  3. 파일 다운로드가 차단되는 경우
  4. 내 컴퓨터의 32비트,64비트 여부 아는법
  5. 'Windows의 PC 보호' 문제
  6. 모두의 프린터 실행후 환경설정창 뜨지 않고 무반응
  7. Ghostscript PDF변환 불가. Can't load Ghostscript DLL
  8. 대법원 인터넷 등기소, 전자소송, 경매,전자공탁등 대법원계열 사이트관련
  9. 모두의 프린터 사용후 네트워크 장애가 발생하는경우. (대법원 인터넷등기소 등)
  10. 출력시 모두의 프린터가 강제종료 되는 경우.'지원하지 않는 PDF또는 가상 프린터입니다.'
  11. 오픽(OPic), 연결상태 확인 불가 프린터, 등록되지 않은 프린터(MarkAny e-PageSAFER)
  12. YBM 토익성적표 관련(정상적인 프린터로 출력을 진행하시기 바랍니다)
  13. 리포트뷰어(ReportViewer) 관련(특수목적프린터, 문서변환 프로그램을 제거해주세요)
  14. 인터넷증명발급센터 서트피아(Certpia) 관련 안내
  15. 인강사이트 관련 - 출력에 매우 오래 걸림, PDF파일 버벅거림, PDF여는데 오래걸림 등등
  16. '잘못된 프린터 데이터를 수신하였습니다.' 문제
  17. MS서피스, 삼성 갤럭시북 등 ARM기반 랩탑, '잘못된 프린터 데이터를 수신하였습니다.' 문제

[GO언어/GOLANG] ed25519 암호화/복호화/서명/검증 알고리즘

특정 데이터의 유효성 검증을 위해서 만든 메소드들입니다. 원래 ECDSA 를 사용하는 놈으로 만들었다가 키를 만드는데 사용되는 P256.. 등의 P시리즈 커브들이 이래저래 말들이 많아서 ED25519를 사용하는 방식으로 변경하였습니다.

ED25519 나 ECDSA는 데이터를 암호화하고 복호화하는데 사용되는게 아니라 특정 데이터에 개인키로 서명(Sign)을 하고 공개키로 서명이 유효한지를 검증해주는 방식으로 사용합니다.

예를들어 데이터가 “피로곰”인 경우에 서버에서 “피로곰”에 개인키로 서명을하고 서명되고 암호화된 데이터를 클라이언트에 전송하면 클라이언트에서는 “피로곰”과 서버에서 보내준 서명된 데이터를 가지고 공개키로 검증을 합니다. 

애초에 사인하기 전의 원본 데이터를 모르거나 원본데이터를 알아도 서명이 검증되지 못하면 문제 있는 데이터가 되버리는 것이지요..

내가 알고 있는 이 값이 .. 정말 상대가 보낸 값이 맞는가를 검증하는데 사용하시면 되겠습니다.

Go
//
// Author: PIROGOM
// https://modu-print.tistory.com
// mop.pirogom@gmail.com
// MIT License 
//
package main

import (
	"crypto/ed25519"
	"crypto/rand"
	"crypto/sha256"
	"encoding/hex"
	"encoding/pem"
	"errors"
	"fmt"
	"io/ioutil"
)

type ECDSAHelper struct {
	PrivateKey *ed25519.PrivateKey
	PublicKey  *ed25519.PublicKey
}

/**
*	Generate
**/
func (e *ECDSAHelper) Generate() error {

	if e.PrivateKey != nil {
		e.PrivateKey = nil
		e.PublicKey = nil
	}

	publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)

	if err != nil {
		return err
	}

	e.PrivateKey = &privateKey
	e.PublicKey = &publicKey
	return nil
}

/**
*	EncodePrivateKey
**/
func (e *ECDSAHelper) EncodePrivateKey() ([]byte, error) {
	if e.PrivateKey == nil {
		return nil, errors.New("private key is nil")
	}

	encBuf := pem.EncodeToMemory(
		&pem.Block{
			Type:  "ED25519 PRIVATE KEY",
			Bytes: *e.PrivateKey,
		})

	return encBuf, nil
}

/**
*	DecodePrivateKey
**/
func (e *ECDSAHelper) DecodePrivateKey(encKey []byte) error {
	if e.PrivateKey != nil {
		e.PrivateKey = nil
	}

	block, _ := pem.Decode(encKey)

	if block == nil {
		return errors.New("failed to find ED25519 PRIVATE KEY")
	}

	if block.Type != "ED25519 PRIVATE KEY" {
		return fmt.Errorf("%s is invalid block type", block.Type)
	}
	e.PrivateKey = (*ed25519.PrivateKey)(&block.Bytes)
	return nil
}

/**
*	PrivateKeyToFile
**/
func (e *ECDSAHelper) PrivateKeyToFile(fname string) error {
	if e.PrivateKey == nil {
		return errors.New("private key is nil")
	}
	enc, err := e.EncodePrivateKey()

	if err != nil {
		return err
	}

	err = ioutil.WriteFile(fname, enc, 0644)

	if err != nil {
		return err
	}
	return nil
}

/**
*	PrivateKeyFromFile
**/
func (e *ECDSAHelper) PrivateKeyFromFile(fname string) error {
	if e.PrivateKey != nil {
		e.PrivateKey = nil
	}

	buf, err := ioutil.ReadFile(fname)

	if err != nil {
		return err
	}

	err = e.DecodePrivateKey(buf)

	if err != nil {
		return err
	}
	return nil
}

/**
*	EncodePublicKey
**/
func (e *ECDSAHelper) EncodePublicKey() ([]byte, error) {
	if e.PublicKey == nil {
		return nil, errors.New("public key is nil")
	}

	encBuf := pem.EncodeToMemory(
		&pem.Block{
			Type:  "ED25519 PUBLIC KEY",
			Bytes: *e.PublicKey,
		})

	return encBuf, nil
}

/**
*	DecodePublicKey
**/
func (e *ECDSAHelper) DecodePublicKey(encKey []byte) error {
	if e.PublicKey != nil {
		e.PublicKey = nil
	}

	block, _ := pem.Decode(encKey)

	if block == nil {
		return errors.New("failed to find ED25519 PUBLIC KEY")
	}

	if block.Type != "ED25519 PUBLIC KEY" {
		return fmt.Errorf("%s is invalid block type", block.Type)
	}

	e.PublicKey = (*ed25519.PublicKey)(&block.Bytes)

	return nil
}

/**
*	PublicKeyToFile
**/
func (e *ECDSAHelper) PublicKeyToFile(fname string) error {
	if e.PublicKey == nil {
		return errors.New("public key is nil")
	}
	enc, err := e.EncodePublicKey()

	if err != nil {
		return err
	}

	err = ioutil.WriteFile(fname, enc, 0644)

	if err != nil {
		return err
	}
	return nil
}

/**
*	PublicKeyFromFile
**/
func (e *ECDSAHelper) PublicKeyFromFile(fname string) error {
	if e.PublicKey != nil {
		e.PrivateKey = nil
	}

	buf, err := ioutil.ReadFile(fname)

	if err != nil {
		return err
	}

	err = e.DecodePublicKey(buf)

	if err != nil {
		return err
	}
	return nil
}

/**
*	Sign
**/
func (e *ECDSAHelper) Sign(msg string) ([]byte, error) {
	if e.PrivateKey == nil {
		return nil, errors.New("private key is nil")
	}

	hash := sha256.Sum256([]byte(msg))
	signed := ed25519.Sign(*e.PrivateKey, hash[:])

	return signed, nil
}

/**
*	SignToString
**/
func (e *ECDSAHelper) SignToString(msg string) (string, error) {
	signed, err := e.Sign(msg)

	if err != nil {
		return "", err
	}
	return hex.EncodeToString(signed), nil
}

/**
* SignToPEM
**/
func (e *ECDSAHelper) SignToPEM(msg string, blockType string) ([]byte, error) {
	signed, err := e.Sign(msg)

	if err != nil {
		return nil, err
	}

	encBuf := pem.EncodeToMemory(
		&pem.Block{
			Type:  blockType,
			Bytes: signed,
		})

	return encBuf, nil
}

/**
*	SignFromPEM
**/
func (e *ECDSAHelper) SignFromPEM(pemBuf []byte, blockType string) ([]byte, error) {
	block, _ := pem.Decode(pemBuf)

	if block == nil {
		return nil, errors.New("failed to find ED25519 PUBLIC KEY")
	}

	if block.Type != blockType {
		return nil, fmt.Errorf("%s is invalid block type", block.Type)
	}

	return block.Bytes, nil
}

/**
*	IsValidSignPEM
**/
func (e *ECDSAHelper) IsValidSignPEM(pemBuf []byte, blockType string) bool {
	block, _ := pem.Decode(pemBuf)

	if block == nil {
		return false
	}

	if block.Type != blockType {
		return false
	}
	return true
}

/**
*	Verify
**/
func (e *ECDSAHelper) Verify(msg string, signed []byte) bool {
	if e.PublicKey == nil {
		return false
	}
	hash := sha256.Sum256([]byte(msg))

	return ed25519.Verify(*e.PublicKey, hash[:], signed)
}

/**
*	VerifyString
**/
func (e *ECDSAHelper) VerifyString(msg string, signed string) bool {
	byteSigned, err := hex.DecodeString(signed)

	if err != nil {
		return false
	}

	return e.Verify(msg, byteSigned)
}
많이 찾는 글들...
  1. PC App Store 제거 방법
  2. Ghostscript/GhostPCL 설치 안내
  3. 파일 다운로드가 차단되는 경우
  4. 내 컴퓨터의 32비트,64비트 여부 아는법
  5. 'Windows의 PC 보호' 문제
  6. 모두의 프린터 실행후 환경설정창 뜨지 않고 무반응
  7. Ghostscript PDF변환 불가. Can't load Ghostscript DLL
  8. 대법원 인터넷 등기소, 전자소송, 경매,전자공탁등 대법원계열 사이트관련
  9. 모두의 프린터 사용후 네트워크 장애가 발생하는경우. (대법원 인터넷등기소 등)
  10. 출력시 모두의 프린터가 강제종료 되는 경우.'지원하지 않는 PDF또는 가상 프린터입니다.'
  11. 오픽(OPic), 연결상태 확인 불가 프린터, 등록되지 않은 프린터(MarkAny e-PageSAFER)
  12. YBM 토익성적표 관련(정상적인 프린터로 출력을 진행하시기 바랍니다)
  13. 리포트뷰어(ReportViewer) 관련(특수목적프린터, 문서변환 프로그램을 제거해주세요)
  14. 인터넷증명발급센터 서트피아(Certpia) 관련 안내
  15. 인강사이트 관련 - 출력에 매우 오래 걸림, PDF파일 버벅거림, PDF여는데 오래걸림 등등
  16. '잘못된 프린터 데이터를 수신하였습니다.' 문제
  17. MS서피스, 삼성 갤럭시북 등 ARM기반 랩탑, '잘못된 프린터 데이터를 수신하였습니다.' 문제

모두의프린터에서 더 알아보기

지금 구독하여 계속 읽고 전체 아카이브에 액세스하세요.

계속 읽기