Skip to main content

성적 여정을 위한 보안 MAC

승인 워크플로우를 설정하거나 성적부 추출을 할 때 Secure REST API를 활성화하면 MAC 보안 메커니즘이 선택 가능한 옵션 중 하나입니다.

MAC값을 생성하고 검증합니다.

API 키 값이 예상한 값인지 확인하고, MAC 매개변수 값을 검증하세요.

  1. API 키 및 기타 매개변수를 매개변수 이름에 따라 알파벳 순으로 정렬하십시오.

  2. 매개변수 값을 순서대로 하나의 문자열로 연결하세요.

  3. Grade Journey 설정 화면에서 얻은 문자열에 공유된 비밀 값을 추가합니다.

  4. MD5 알고리즘을 사용하여 문자열을 16바이트 문자열로 암호화합니다(다음 예시 참조).

  5. 16바이트 문자열을 URL 지원이 가능한 32바이트 영숫자(16진수) 문자열로 변환하세요.

  6. 생성된 MAC과 요청에서 전달된 Blackboard에서 생성된 MAC을 비교해 보세요.

자바 예시

/**
* Calculates a secure MAC (message authentication code) from an array of strings and
shared secret.
* @param values – Parameters must first be sorted alphabetically by parameter name, then
the values of these sorted parameters passed to calculateSecureMac
* @param secret - the shared secret
* @return The calculated MAC
*/
private String calculateSecureMAC (final String[] values, final String secret) throws
NoSuchAlgorithmException
{
// concatenate param values
final int size = values.length;
String paramString = "";
for(int i=0; i<size; i++)
{
paramString += values[i];
}
// get md5 hash from ascii value and secret
final MessageDigest md = MessageDigest.getInstance("MD5");
final byte[] hashBytes = md.digest((paramString + secret).getBytes());
md.reset();
// convert to hex
String mac = "";
String hexByte;

for (int k=0; k<hashBytes.length; k++)
{
hexByte = Integer.toHexString(hashBytes[k] < 0 ? hashBytes[k] + 256 : hashBytes[k]);
mac += (hexByte.length()==1) ? "0" + hexByte : hexByte;
}
return mac;

PHP 예시

/* Calculates a MAC (message authentication code) from an array of strings and a secret.
Sort request parameters alphabetically by parameter name first, then pass values of sorted
parameters and shared secret to calculateSecureMac */
function calculateSecureMac($params, $secret)
{
// concatenate param values
$data = implode('', $params);
// get md5 of concatenated param values and secret
$mac = md5($data . $secret);
return $mac;
}

Perl 예시

use Digest::MD5;
# Calculates a MAC (message authentication code) from an array of strings and a secret. Sort request parameters alphabetically by parameter name first, then pass values of sorted parameters and shared secret to calculateSecureMac
sub calculateSecureMac
{
my @args = @_;
$secret = pop(@args);
# concatenate param values
$data = join("", @args);
# get md5 of concatenated param values and secret
$ctx = Digest::MD5->new;
$ctx->add($data . $secret);
$mac = $ctx->hexdigest;
return $mac;
}