wolfyflutter

pddikti [search]

Jun 30th, 2025 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.48 KB | Source Code | 0 0
  1. // skrep lama, sorry kalauu kodenya jelek hehe
  2.  
  3. const CryptoJS = require('crypto-js');
  4.  
  5. const decrypt = (encryptedText) => {
  6.     //param encryptedText, type String, content pddikti encrypted text
  7.     //return object
  8.    
  9.     //web constant
  10.     const webSecretKey = "ecHyOABV9jgO2/+dzE49cfexQpr/H4SiAYWrHLD7PQ0="
  11.     const webInitializationVector = "Gu3qsglYJhOOm0eXf6aN2w=="
  12.  
  13.     //begin decrypt
  14.     const secretKey = CryptoJS.enc.Base64.parse(webSecretKey)
  15.     const initializationVector = CryptoJS.enc.Base64.parse(webInitializationVector)
  16.     const wordArray = CryptoJS.AES.decrypt(encryptedText, secretKey, {
  17.         iv : initializationVector
  18.     })
  19.     const decryptedText = wordArray.toString(CryptoJS.enc.Utf8)
  20.     return JSON.parse(decryptedText)
  21. }
  22.  
  23. const searchData = async (query) => {
  24.     if (!query.length) throw Error ("keyword nya kagak boleh kosong.")
  25.     const api = "https://api-pddikti.kemdiktisaintek.go.id/pencarian/enc/all/"
  26.     const res = await fetch(api + encodeURIComponent(query))
  27.     if (!res.ok) throw Error (`your request is not ok! ${res.status} ${res.statusText}`)
  28.     const encryptedData = await res.json()
  29.     const data = decrypt(encryptedData)
  30.     if (data.mahasiswa === null) throw Error (`gak ada mahasiswa degnan hasil pencarian ${query}`)
  31.     return data
  32. }
  33.  
  34. (async()=>{
  35.     try{
  36.         const result = await searchData("halo")
  37.         console.log(result)
  38.     }catch(error){
  39.         console.log(error.message)
  40.     }
  41. })()
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
Tags: search pddikti
Add Comment
Please, Sign In to add comment