Oracle Database replacement Encryption Algorithm

Source: Internet
Author: User

The principle of replacing the cryptographic algorithm is to use the replacement method for encryption, that is, replacing characters in plain text with other characters to form the ciphertext. For example, the plaintext letters a, B, c, and d are replaced with D, E, F, and G to form the ciphertext.

Here, in the Oracle stored procedure, the encryption algorithm is replaced to encrypt the password stored in the database.

1 .--------------------------------

2 .--------------------------------

3. -- Oracle database encryption ---- substitution algorithm ---

4. -- http://nileader.blog.51cto.com

5 .--------------------------------

6. create or replace procedure pro_insert (

7. uName IN scott. users. uname % TYPE, -- User Name

8. uPwd IN scott. users. upwd % TYPE -- password, which must be encrypted

9.) IS

10. BEGIN

11.

12. -- define variables

13. DECLARE

14. insertSQL nvarchar2 (200); -- an SQL statement to be constructed

15. key numeric (2); -- key

16. totalLetter numeric (2); -- total number of letters

17. targetCode nvarchar2 (15); -- indicates the converted character and password

18. lengthUpwd numeric (2); -- password length

19. initCodeVal numeric (3); -- value corresponding to each character in the original password

20. targetCodeVal numeric (3 );

21. BEGIN

22.

23. key: = 3; -- key assignment

24. totalLetter: = 26; -- total number of letters

25. targetCode: = ''; -- converted character

26.

27.

28. -- get the length of the initial key

29. lengthUpwd: = LENGTH (uPwd );

30.

31. -- encrypt the initial key one by one

32. FOR I IN 1... lengthUpwd

33. LOOP

34.

35. initCodeVal: = ASCII (SUBSTR (uPwd, I, 1)-96;

36. -- if the replacement letter exceeds z

37. targetCodeVal: = MOD (initCodeVal + key), totalLetter );

38.

39. -- for z

40. IF targetCodeVal = 0 THEN

41. targetCodeVal: = 26;

42. end if;

43.

44. targetCodeVal: = targetCodeVal + 96;

45.

46. -- assemble encrypted characters

47. targetCode: = targetCode | CHR (targetCodeVal );

48. end loop;

49.

50. -- construct an SQL statement

51. insertSQL: = 'insert INTO users (uName, uPwd) VALUES ('''

52. | uName | ''', ''' | targetCode | ''')';

53. execute immediate TO_CHAR (insertSQL );

54.

55. END;

56. END pro_insert;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.