BookmarkSubscribeRSS Feed

[Groovy] 자바 암호화 class를 사용하여서 SAS 데이터 암호화 하기

Started ‎06-15-2020 by
Modified ‎06-15-2020 by
Views 180

자바 Class를 Proc groovy 프로시져를 통하여 호출하여서 SAS 데이터 세트를 암호화 하는 프로그램입니다. 제가 Java를 잘 몰라서 자세한 설명은 못하겠지만, Proc Groovy 프로시져를 통하여 자바 프로그램을 SAS에서 호출하여서 사용가능 할 듯 합니다. 참고하시기를 바랍니다.

 

 

* 예제1 출처 : https://gist.github.com/FriedEgg/79ad315afa1b315e8ac3;

 

/* This is to encode items in a data set instead of a macro variable, using javaobj */

 

* SHA(Secure Hash Algorithm, 안전한 해시 알고리즘) 함수들은 서로 관련된 암호학적 해시 함수들의 모음;

 

* SHA1 암호화;

filename cp temp;

proc groovy classpath=cp;

  submit parseonly;

    import java.security.MessageDigest

    class Sha1 {

      public String encode(String message) {

        return new BigInteger(1, MessageDigest.getInstance("SHA1").digest(message.getBytes())).toString(16);

      }

    }

  endsubmit; 

quit;

 

* groovy 프로시져에서 사용하던 classpaht 설정;

options set=classpath "%sysfunc(pathname(cp,f))";

 

data class1;

     * Sha1 class 호출;

     dcl javaobj sha1('Sha1');

     do until (done);

        set class end=done;

        length encoded_name $ 40;

        sha1.callStringMethod('encode', strip(name), encoded_name);

        output;

     end;

run;

 

 

 

* 예제2 출처 : https://communities.sas.com/t5/Base-SAS-Programming/Enable-SHA1-Hash-MessageDigest-in-SAS-with-Javao...;

 

filename cp temp;

proc groovy classpath=cp;

     submit parseonly;

       import java.math.BigInteger;

       import java.security.MessageDigest;

       import java.security.NoSuchAlgorithmException;

       public class Sha1 {

           public static String text;

           public static void main(String[] args) throws NoSuchAlgorithmException {

               for (String item : args) {

                   text = item;

                   System.out.println("Text: " + item + " SHA1: " + getSha());

               }

           }

           public static String getSha() throws NoSuchAlgorithmException {

               byte[] digest = MessageDigest.getInstance("SHA1").digest(text.getBytes());

               return new BigInteger(1, digest).toString(16);

           }

       }

       endsubmit;

quit;

 

data foo;

     length text sha1 $40;

     declare javaobj s('Sha1');

     do text='abc','abcd';

        s.setStaticStringField('text',text);

        s.callStaticStringMethod('getSha',sha1);

        put 'Text: ' text ' SHA1: ' sha1;

        output;

     end;

run;

 

data class; 

     if 0 then set sashelp.class;

     length sha1 $40;

     declare hash c(dataset:'sashelp.class',ordered:'y');

     declare hiter i('c');

       c.definekey('sex','name');

       c.definedata(all:'y');

       c.definedone();

 

     declare javaobj j('Sha1');

     _n_=i.first();

     do while(_n_=0);

        j.setStaticStringField('text',name);

        j.callStaticStringMethod('getSha',sha1);

        output; 

        _n_=i.next();

     end;

     stop;

run; 

 

* 출처 : http://cafe.daum.net/statsas/3F8j/320

 

*********************************************************

- 통계분석연구회
- 통계분석연구회(Statistics Analysis Study) 그룹 :https://www.facebook.com/groups/statsas
 

#통계 #빅데이터 #통계분석연구회 #데이터과학자 #bigdata #dataviz #statistics #Analytics

Version history
Last update:
‎06-15-2020 12:48 AM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Article Labels
Article Tags