கடவுள்(இறைவன்) இருக்கிறானா?

இருக்கிறான் என்று இறை-நம்பிக்கை உள்ளவர்களும், இல்லை என்று இறை-மறுப்பாளர்களும்,‘கடவுள் இருப்பதும், இல்லை என்பதும் கதைக்கு உதவாத வெறும் பேச்சு’ என்று உலகாதாயம் பேசுபவர்களும் மூன்று விதத்தில் விடை சொல்வார்கள்.

ஆனால், ‘உயிர்கள்’ உண்டா என்று யாரும் ஐயம் எழுப்புவது இல்லை!

உடல்களில் இயங்கும்போது, பல பெயர்கள் கொண்டு விளங்கும் உயிருடல்கள், உயிர் நீங்கினால், அனைத்து மனித உடல்களுக்கும் ‘பிணம்’ என்ற ஒரே பெயர்தான்.

ஐயா, ஐயா என்று வாஞ்சையாக அழைத்தவர்கள், உயிருடலில் இருந்து, ‘ஐயா’ என்ற உயிர் நீங்கிவிட்டால், ‘ஐயாவை எப்போது எடுப்பார்கள்?’ என்று யாரும் கேட்பதில்லை;
மாறாக, “பிணத்தை எப்போது எடுப்பார்கள்?” என்றுதான் கேள்வி வருவதை சாதாரணமாகக் காண்கிறோம்.

உயிர் நீங்கிய உடல் எரிக்கப்பட்டோ – புதைக்கப்பட்டோ சிதைவுறும்.

எனவே, உயிர் என்ற ஒன்றின் இருப்பை, எவரும் மறுப்பதில்லை. ஆயினும், உலகோர் அனைவரும், உடலை விட்டு நீங்கியதும்,

  1. ‘உயிர்’ என்னவாகிறது?
  2. எங்கே போகிறது?
  3. எப்படி உடலற்ற உயிரின் வாழ்வு அமையும்?

போன்ற வினாக்களை எழுப்பிக் கொண்டதால் வந்த விளைவுகள்தாம் கடவுள்கள் – மதங்கள் – சமயங்கள் – நம்பிக்கைகள் – சாமியார்கள் – பேய்கள் – செய்வினை – மந்திரங்கள் என்ற பலவும்.

உடல் வாழ்க்கைக்கு அப்புறம், உயிரின் நிலை என்ன என்ற கேள்வியின் விளைவே பல்வேறு சமயத் தத்துவங்கள்.

எனவே, உயிர்கள் என்றால் என்ன என்ற கேள்வி, மிகவும் பொருத்தமானதே! என்றாலும், உயிர்களுக்கும், இவ்வுலகத்துக்கும், இறைவன் என்னும் தத்துவப் பொருளுக்கும் உள்ள
தொடர்புக்கான விடை காண முயல்வதே, சமயங்கள் அல்லது மதங்கள் அனைத்துக்கும் இடையே இருக்கும் பொதுவான கூறு.

எனவே, உயிர் என்றால் என்ன? என்ற கேள்விக்கு,

  1. இறைவன் என்றால் என்ன?
  2. உயிர்-உலகம்-இறைவன் இவற்றிற்கான தொடர்பு என்ன?

இணைத்தே விடை காண முயலவேண்டும்.

இறைவன், உயிர்கள், உலகம் என்ற மூன்று பொருட்களையும், அவற்றிற்கு இடையேயான உறவுகளையும் அறுதியிட்டு, வரையறை செய்த சைவ சித்தாந்தம் என்னும் தத்துவத்தின் மூலம் உங்கள் கேள்விக்கு விடை தர முயற்சிக்கிறேன்.

இப்பிரபஞ்சத்தின் ‘முப்பெரும் உண்மைகள்’ என்று மூன்று பொருட்கள் சுட்டப்படுகின்றன.

‘முப்பெரும் உண்மைகள்’

  1. இறைவன்(பதி)
  2. உயிர்கள்(பசு)
  3. தளைகள்(பாசம்)

எனப்படும்.

அகன்று எல்லையில்லாமல் விரிந்துகொண்டே செல்லும் (ever expanding universe) பரவெளியின் அனைத்தும் இம்மூன்று பொருட்களில் அடக்கம் என்கிறது சைவசித்தாந்தம் என்னும் சிவனியத்தத்துவம்.
உயிர்கள்(பசுக்கள்) இயல்பு!
உயிர்கள் அறிவுப்பொருட்கள்!

உயிர்கள் சார்ந்தவண்ணம் ஆதல் தன்மை கொண்டவை!(உயிரைப் பச்சோந்தி என்கிறீர்களா? ஆம், கிட்டத்தட்ட அப்படித்தான். உடலைச் சார்ந்து இருப்பதால், தான் என்பது உடலே என்று உணரும் உயிர்; உடலுக்கு நோய் வரும்போது, உயிர் அந்நோய் தனக்கே வந்தது என்று மயங்கும்.உடல்-மனம் மகிழ்வாக/சோகமாக இருக்கும்போது, உலகமே மகிழ்வாக /சோகமாக இருப்பதுபோல் எண்ணும்.அப்படியானால், உயிர் வேறு-உடல் வேறா? ஆம், என் கை, என் கால், என் உடலுக்கு முடியவில்லை என்று சொல்வதெல்லாம் என்னவாம்? உயிர் வேறு, உடல் வேறு என்பதால்தானே என் உடம்புக்கு முடியவில்லை என்கிறோம்!)

உயிர்கள் அறிவித்தால் மட்டுமே அறிபவை! (அப்படியா? சரியாகத்தான் படுகிறது. உயிர் அறிந்ததெல்லாம், கண்டும், கேட்டும், சுவைத்தும்,நுகர்ந்தும், தொட்டுஉணர்ந்தும் அறிந்தவை அல்லவா? அப்படியானால், எனது அறிவுக்கு, என் உடல்தான் மூலக்கருவியா? புரிந்தால் சரிதான். உடல் சார்ந்த மனம், புத்தி, சித்தம், அகங்காரம் என்றெல்லாம் இன்னும் சில உண்டு. பின்னர் குழம்பி, விளக்கித் தெளியலாம்.)

உயிர்கள் என்றும் உள்ளவை! (அப்படியானால், உயிர் போகிறது; சாவு வருகிறது எப்படி? பின்னர் விளக்குவோம்);

உயிர்கள் யாராலும் படைக்கப்படாதவை ! (கடவுள் படைக்காததா உயிர்கள்? தந்தை பெரியார் பேச்சை வைத்து காமெடி ஒன்றும் செய்யவில்லையே? உறுதியாக இல்லை. சைவசித்தாந்தத் தத்துவம் சொல்வதைத்தான் சொல்கிறேன்);

  1. உயிர்கள் எண்ணற்றவை! (infinity – முடிவிலி என்று கணிதத்தில் சொல்வோமே, அதேதான். -∞ to +∞)
  2. இதுவரை எத்தனை உயிர்கள் உடல்பிறவிகள் பிறந்து-இறந்துள்ளன? எண்ணற்றவை. (minus infinity: -∞)
  3. இன்னும் எத்தனை உயிர்கள் பிறக்க இருக்கின்றன? எண்ணற்றவை. (plus infinity:+∞)
  4. ஒரு உயிர் எத்தனை உடல் பிறவிகள் எடுக்கவேண்டும்? அந்தந்த உயிரின் வினைப்பயன்களைப் பொறுத்தது. (அப்ப, ஏழு பிறவி என்பதெல்லாம் பொய்யா? அது ஏழு பிறவி இல்லை. எழு பிறவி! அதாவது, வினைப்பயன்களுக்கு ஏற்றவாறு எழுகின்ற பல பிறவிகள். )
  5. உயிர்கள், தன் இயல்பில், அறியாமை(ஆணவம்) என்னும் நுண்ணிய சடப்பொருளால் மறைக்கப்பட்டு, எங்கும் நிறையும் தன்மை இல்லாமல், கட்டுப்பட்டு மயங்கிக் கிடக்கும் குற்றம் உடையவை; அறிவித்தால் அறிபவை.

உயிர் எவ்வாறு இந்த உடல்-பிறவிக்கு வந்தது?
இறைவனால் என்கிறது சைவ சித்தாந்தம். இயற்கையால் என்கிறது அறிவியல்.

இனி, இறைவன் குறித்த கேள்விக்குச் செல்லலாம்.
இறைவன்(பதி) இயல்பு
இறைவன் (பதி) – ஒருவனே – என்றும் உள்ளவன் – தன் இயல்பில், யாரும் அறிவிக்காமல் அறியும் ஆற்றல் கொண்ட அறிவே வடிவானவன் – எல்லையற்ற ஆற்றல் கொண்டவன்.
கருணையே வடிவானவன் – வேண்டும்போது, வேண்டும் உருவம் கொள்ளும் ஆற்றல் கொண்டவன் – பொறிகள் புலன்கள் கொண்ட உடல்பிறவிக்கு வாராதவன் – எங்கும் நிறைந்தவன் –

தளைகள்(பாசம்) இயல்பு
தளைகள்(பாசம்) என்றும் உள்ள அறிவற்ற சடப்பொருளாகிய குற்றம் ஆகும்.
பாசம் என்ற தளை, ஆணவம், கன்மம், மாயை என்ற மூன்று வடிவங்களில் காணப்படும் – செம்புக்குக் களிம்பு போல் தன்னியல்பில், ஆணவம் உயிர்களைக் கட்டுவிக்கும் ஆற்றல் கொண்டவை.

உடலால் கட்டப்பட்ட உயிர், தன் உடலே தான் என்று கருதுவதை முன்னரே பார்த்தோம்.
இறைவன் அணுகினால், தளைகள்(பாசங்கள்) உயிர்களை விட்டு நீங்கும் இயல்பின.(ஆணவம், கன்மம், மாயை என்னும் மூவகைத் தளைகள் (பாசங்கள்-3) குறித்துப் பிற்பகுதியில் விரிவாக விளக்கியுள்ளேன்)

உயிர்கள் பால் இறைவனின் கருணை!

எல்லையற்ற கருணையாளன் இறைவன்,
• அறியாமையால் கட்டுண்ட உயிர்கள் மீது கொண்ட அன்பால், அவற்றைப் பிடித்த அறியாமை (ஆணவம்) நீங்க,
• உலகங்களைப் படைத்து, உலகங்களில் இயங்கும் உடல்களைப் படைத்து,
• அவ்வுடல்களில் உயிர்கள், தாமே இயங்கி, உடல்களில் பொருந்தியுள்ள பொறி-புலன்கள் வாயிலாக,
• புற உலகையும், பின்னர், தன்னை அறியும் அக-உலகையும் அறியும்படி
வாய்ப்புகள் வழங்குகிறான்.
திரோதான சக்தியும், அருட்சக்தியும்!
இப்படியான வாழ்க்கை முறையில், இறைவன் உயிர்களுடன் மறைந்து இருப்பது திரோதானம்(மறைப்புச்சக்தி) எனப்படும்.
தன்னை அறியும் உயிர்கள், தம் தலைவனாம் இறைவனை அறிதல் வேண்டித் தொழும்போது, இறைவன் வெளிப்பட்டுத் தோன்றி, உயிர்களின் இயல்பான முற்றறிவு என்னும் ஞானத்தை அருள்வான்; சீவன் என்னும் உயிர் சிவமாகும் வேளையில், அதற்கு, உடல் கருவி தேவை நீங்கும். சிவமாகும்.
அவ்வாறு,இறைவனால் அறியாமை நீங்கப் பெற்ற உயிர்கள், தம் தலைவன் இறைவனை அறிந்து, எங்கும் நிறையும் (வியாபகம்) சிவமாம் தன்மை பெற்று, சிவத்துடன் இரண்டறக் கலக்கும்.

இறைவன், உயிர்கள், உலகம்(இயற்கை-பேரண்டம் அனைத்தையும் உள்ளடக்கியது) என்ற மூன்று பொருட்களையும், அவற்றிற்கு இடையேயான உறவுகளையும் அறுதியிட்டு, வரையறை செய்த தத்துவமே சைவ சித்தாந்தம் எனப்படும்.

உலகம்-என்பது, மூன்று பொருட்களை ஒண்ணாக்கிச் சொன்னது என்பதை நினைவில் கொள்க!

பஞ்ச பூதங்கள்
முதலாவது செய்தி: உயிரற்ற சடப்பொருள் உலகம் என்பது, நிலம், நீர், தீ, காற்று, வெளி (வானம்) என்ற ஐந்து பொருட்களும் கொண்ட கலவை. ‘பஞ்ச பூதங்கள்’

ஐந்து அறியும் கருவிகள் – புலன்கள்

உயிர் என்ற அறிவுப்பொருளுக்கு, அறிவு கொடுக்கும் கருவியாக, இறைவனால் கொடுக்கப்பட்ட கருவி(Gadget)தான் நம் உடம்பு என்னும் உடல் – அதில், Five sensors-களும், Five senses-களும் உண்டு. (உடல்(மெய்) -touch sensor(தொட்டால் உணர்தல் கருவி, touch sense), வாய்-நாக்கு -taste sensor(சுவை உணரும் கருவி, taste sense), கண் – vision sensor(ஒளி பார்க்கும் பார்வைக் கருவி, vision sense), மூக்கு – sniffing sensor(மோப்பக் கருவி, sniffing sense), செவி – hearing sensor(ஒலி கேட்கும் கருவி, hearing sense)
நன்றாக சிந்தித்துப் பாருங்கள்! நமது அறிவு-என்பது இந்த ஐந்து அறியும் கருவிகள் – புலன்கள் இல்லாமல் நடக்குமா-என்று.

ஐந்து நுண்ணிய புலன்கள் (தன்மாத்திரைகள்)
இந்த ஐந்து அறியும் கருவிகளான மெய், வாய், கண், மூக்கு, செவி என்ற பொறிகளுக்கும், சுவை(த்தல்), ஒளி(பார்த்தல்), ஊறு(உணர்தல்), நாற்றம்(நுகர்தல்), ஓசை(கேட்டல்) என்னும் ஐந்து நுட்பமான புலன்கள் உண்டு.
ஐந்து தொழிற் கருவிகள் (கன்மேந்திரியங்கள்)
வாய் (பேச்சு/வாக்கு), கை(பாணி), கால்(பாதம்), எருவாய்(பாயு), கருவாய்(உபத்தம்) மனம் – புத்தி – சித்தம் -அகங்காரம்!

இந்த ஐந்து அறிகருவிகளையும், ஐந்து புலன்களையும் ஒருங்கிணைத்து செயலாற்றும் மனம் என்னும் கருவி, தகவல்களை மூளைக்கு அனுப்புகிறது.
மூளைக்குள் வந்த தகவல்கள் யாவை என்று ஏற்கனவே மூளையில் உள்ள தகவல்களுடன் ஒப்பிட்டு அறியும் கருவி ‘புத்தி’ எனப்படும். (இதுவும் வடமொழி சொல்லே!)
தீ எரிவதை, கண் என்ற பொறி கொண்டு பார்த்த மனம் தந்த தகவலை, ஏற்கனவே மூளையில் பதிந்துள்ள தகவலுடன் ஒப்பிட்டு, தீதான் என்று புத்தி சொல்லியதும்,

  1. தீயை நீரைக் கொண்டு அணைக்கும் செயலைச் செய்யலாம் என்று பரிந்துரை செய்கிறது, சித்தம் என்னும் கருவி;
  2. ‘ஆம், நான் தீயை நீரைக் கொண்டு அணைக்கப் போகிறேன் என்று ‘முடிவு செய்கிறது’ அகங்காரம் என்னும் கருவி;
  3. ‘நீர் இருக்கும் தொட்டியை நோக்கி ஓடு’ என்று காலுக்குக் கட்டளை இடுகிறது; ‘வாளியை எடுத்து, நீரை முகர்ந்து ஊற்று’ என்று கைகளுக்குக் கட்டளை இடுகின்றது.
  4. ‘சேகர், நீயும் இன்னொரு வாளியில் நீரை எடுத்து ஊற்று’ என்று வாய்க்குக் கட்டளை இடுகின்றது;
  5. இப்படி, இரண்டு கைகள், இரண்டு கால்கள், ஒரு வாய், கழிவுகளை வெளியேற்றும் எருவாய், விந்து-நாதம் கருவாய் ஆகிய ஐந்தும் ஏவல் வேலை செய்யும் இயந்திரங்கள் என்பதால்,வேலை-இயந்திரங்கள் – தொழிற்கருவிகள் ஐந்து என்கிறோம். (வடமொழியில், கர்மேந்திரியங்கள் ஐந்து)

இவ்றோடு மனம், புத்தி, சித்தம், அகங்காரம் (அந்தகரணங்கள்)என்னும் நான்கு தத்துவங்கள்.

சைவசித்தாந்தம் சொல்லும் 36 தத்துவங்கள்!

ஐந்து பருப்பொருட்கள்(பூதங்கள்), ஐந்து அறி-கருவிகள், ஐந்து அறி-புலன்கள், ஐந்து தொழிற்கருவிகள், நான்கு அந்தகரணங்கள் என்னும் இந்த இருபத்துநான்கு தத்துவங்களோடு வித்தியா தத்துவங்கள் 7, சிவதத்துவங்கள் 5 கூட்டி வரும் 12 தத்துவங்களையும் (பின்னர் விளக்குகிறேன்; இப்போதைக்கு, பதி,பசு,பாசம் அறிவோம்) சேர்த்து 36 தத்துவங்கள் என்பது சைவ சமய, சைவ சித்தாந்தத்தின் முடிபு ஆகும். (நாம் அறிந்து கொண்ட முடிபு – கொண்முடிபு)

ஆணவம், கன்மம், மாயை என்ற மூன்று வகைப் பாசங்கள்-பாசம்!

  1. உயிர்களை இயல்பாகப் பற்றியுள்ள அறியாமை (ஆணவம்),
  2. உயிர்களின் அறியாமையை(ஆணவத்தை) அகற்ற இறைவன் தந்த அறிவுக் கருவிகளான 24 தத்துவங்கள் வழியாக உயிர்கள் வினைகள் செய்து செயலாற்றுவதால், விளையும் வினைப் பயன்கள் (கன்மம்/கருமம்),
  3. அறியாமை நீக்கவே, இறைவன் மாயை வழியாக, உலகம் என்னும் University-யில், உடல்-என்னும் Hostel-லில், வாழ்க்கை என்னும் 100 ஆண்டு Course படிக்க அனுப்புகிறான்.
    வந்த வேலையை விட்டுவிட்டு, உழைப்பதெல்லாம் உணவின் பொருட்டே-என்று உழல்கிறோம்!
  4. University-ல சேர்ந்தோமா, hostel-லுக்குப் போனோமா, படிச்சு முடிச்சு, Degree என்ற ஞானத்தைப் பெற்று, இறைவனுடன் இரண்டறக் கலத்தல் என்னும் நிலையான வேலைக்கு முயற்சி செய்யாமல்,
    • Hostel சாப்பாட்டையே ருசிச்சுச் சாப்பிட்டுவிட்டு,
    • hostel என்னும் உடலிலேயே வாழ என்ன வழின்னு யோசிச்சு, வாழ்க்கையை வீணாக்கி, வினையை சம்பாதிச்சு,
    • fail-ஆகி, கருமவினைகளைத் தீர்க்க மீண்டும், மீண்டும் University என்னும் உலகத்துக்கு வந்து,
    • Hostel-என்னும் உடலில் மீண்டும் நுழைந்து, மீண்டும் fail ஆகி, சுத்திக்கிட்டே இருக்கோம்.

நாம இந்த உலகத்துக்கு வந்த வேலையைப் பார்க்காமல், அறியாமை என்னும் ஆணவத்தால், வினைகளை ஈட்டி, மீண்டும், மாயையால், பிறந்து, இறந்து உழல்கிறோம்.
இறைவனை அறியும்முழுமையான அறிவே முழு விடுதலை!

இந்த அறியாமை(ஆணவம்), வினைகள்(கன்மம்) காரணங்களாக,

  1. மீண்டும் பாசம் என்னும் ஆணவம், கன்மம், மாயையில் சிக்காமல் விடுபட,
  2. மனிதன் முயற்சி செய்து, இறைவனிடம் அடைக்கலம் புகவேண்டும்;

சக உயிர்களுக்கும், மனிதர்களுக்கும், கருணையும், தொண்டும் செய்வோருக்கு, இறைவன் அருள்கிறான்.
இறைவனுடன் கலத்தலே பாசத்திலிருந்து விடுதலை பெற வழி!
அறியாமை,(ஆணவம்), நல்வினை-தீவினைகள்(கன்மம்), மாயை ஆகிய பாசத்திலிருந்து உயிர்கள் விடுதலை பெற, இறைவனை அடைவது ஒன்றே ஒரே வழி என்பதைத் திருமந்திரம் அழகாக விளக்குகிறது.

பதி பசு பாசம் எனப் பகர் மூன்றில்
பதியினைப் போல், பசு பாசம் அநாதி!
பதியினைச் சென்று அணுகாப் பதிபாசம்
பதி அணுகில் பசுபாசம் நில்லாவே!
– திருமந்திரம்.

இறைவனைப்போல் உயிர்களும் ஆதி-அந்தம் இல்லாதவை!
இறைவன்(பதி), உயிர்கள்(பசு), தளைகள்(பாசம்) என்ற மூன்றையும் குறித்துச் சொல்வதானால், இறைவனைப் போலவே, உயிர்களும், தளைகளும், தொடக்கம், முடிவு இல்லாதவை!

உயிர்கள் இறைவனுக்குச் சமமா?

  1. பாருங்கள்! இறைவனைப்போல், உயிருக்கும் தொடக்கம்-முடிவே இல்லை!
  2. அப்படியானால், நமக்கும், இறைவனுக்கும் வித்தியாசம் இல்லை என்று கருதலாம் அல்லவா?
  3. நாமும், இறைவனும் சமம்தானோ என்று தவறாகக் கருத வேண்டாம்!
  4. இதைத்தானே வேதாந்தியும் சொல்லிக் குழப்பினார் என்று நினைக்க வேண்டாம்.

அடுத்த வரியில் அழகாக விளக்குகிறார் பாருங்கள்.
இறைவனை பாசங்கள் அணுகாது!

• ஆனால், பாசம் என்னும் தளைகள், இறைவனை (என்னும் பதியினைச் சென்று) அணுகக் கூட இயலாது.
• இறைவன் பாசங்கள் அணுக முடியாத தூய முழுமையான அறிவினைக் கொண்டவன்.
(முற்றுமான அறிவைக் கொண்டவன் என்ற பொருளில், முற்றறிவன் – வாலறிவன் என்று இறைவனைச் சொல்லுவோம். அவனுக்கு, ஐம்பொறி-புலன்கள் கொண்ட உடல் தேவையற்றவன்; அனைத்தையும் உடல் இல்லாமலேயே அறிபவன்; எங்கும் நிறைந்தவன்; உங்கள் உள்ளும், என்னுள்ளும் நிறைந்தவன்)
உயிர்களின் அறியாமை மலங்கள்(பாசம்) நீக்கவே உடல்-பிறவி!
எனவே, இயல்பாகவே,

  1. அறியாமை(ஆணவம்) என்ற பாசம் பிடித்தே இருக்கும் உயிர்களின் அறியாமையைப் போக்கவே,
  2. உடல்கள் கருவிகளைத் தந்து,
  3. உலகம் என்னும் அறிவுக்கூடத்தில், உலவ விடுகிறான்;
  4. டல்கள் மூலம் அறிவு பெற்று, உடல்களை விட்டு நீங்கும்போது, முற்றறிவன் இறைவனுடன் கலந்தால், உயிர்களுக்கும் உடல்-அறிவு தேவைகள் நீங்கிவிடும்;
    பிறவிகள் நீங்கிவிடும்!
  5. பிறவி-வினை-பிறவி சுழல் நீக்கும் இறைவன்!

பிறவிகள் வினைகளால் வருகின்றன.

  1. பிறவிகளால், வினைகளை ஈட்டுகிறோம்.
  2. முட்டையிலிருந்து கோழி, கோழியிலிருந்து முட்டை என்பதுபோல், வினையால் பிறவிகள், பிறவியால் வினைகள் என்ற சுழலை உடைக்கும் வல்லமை

இறைவனை அணுகினால் மட்டுமே கிடைக்கும் என்று அறிவோம்!
இறைவன்தான் நமக்குள்ளேயே இருக்கானே! அப்ப எப்படி மும்மலங்கள் என்னும் ஆணவம், கன்மம், மாயை நம்மைப் பிடித்தன?

  1. இறைவன் எங்கும் இருப்பதுபோல், நம்முள்ளும் இருக்கிறான்;
  2. நம்முள்ளே அவன் இருந்தாலும், அவனுள்ளே நாம் கலக்கவில்லையே?
  3. அப்படி ஒருவன் நம்ப கூட இருக்கிறான்-னு நாம்தான் கண்டு கொள்வதே இல்லையே!
  4. மனிதன் எப்பவாது நம்பளக் கண்டுக்குவான்; அப்பத்தான், மனிதனை நாம் ஆட்கொள்வோம் என்று இறைவன் காத்துக்கொண்டே இருக்கிறான்.

நம்முள் இருந்தாலும், தூய உடம்பினனான இறைவனை மலங்கள் பிடிக்காது.

  1. ஆக, மும்மலங்கள்(ஆணவம், கன்மம், மாயை) என்னும் தளைகளை ஒழிக்க ஒரே வழி, இறைவனை நாம் நினைந்து அணுகினால் போதும்.
  2. இறைவனின் சந்நிதானத்தில், உயிர்களைப்(பசு) பிடித்துள்ள பசு-பாசம் நில்லாமல் ஓடிப்போகும் என்கிறார் திருமூலர்.

உயிருக்கான விளக்கத்தை சரியாக விளக்கிவிட்டேனா என்று அன்பர்கள்தான் கூற வேண்டும்!

Find the Minimum and Maximum Sum

Input Format
A single line of five space-separated integers.

Constraints

    \[1<arr[i]<10^9\]

Output Format
Print two space-separated long integers denoting the respective minimum and maximum values.

Sample Input

1 2 3 4 5

Sample Output

10 14
  1. Find the Minimum and Maximum Element in array
  2. When you calculate the minSum and maxSum – discard the maxElement and minElement
  3. Trick is you may miss logic if the array contains 5 elements and all are of same value. In such case the maximum and minimum value elements are same
  4. For finding minimum number, start by assigning maximum number to minNum
.
.
 public static void miniMaxSum(List<Integer> arr) {
        long minNum = 0;
        long maxNum = 0;

        long minSum = 0;
        long maxSum = 0;


        //To find maximum Number
        for(int num=0;num<arr.size();num++){
            if(maxNum<=arr.get(num)){
                maxNum = arr.get(num);
            }
        }

        //To find minimum Number
        minNum = maxNum;

        for(int num=0;num<arr.size();num++){
            if(arr.get(num)<=minNum){
                minNum = arr.get(num);
            }
        }

        for(int num=0;num<arr.size();num++){
            //If the array elements are of same value
            if(num!=0 && arr.get(num) == arr.get(num-1)){
                minSum +=arr.get(num);
                maxSum +=arr.get(num);
            }


            if(arr.get(num) != maxNum)
              minSum +=arr.get(num);

            if(arr.get(num) != minNum)
              maxSum +=arr.get(num);
        }

        System.out.println(minSum);
        System.out.println(maxSum);
    }
.
.

Get Count of biggest Element in array – Total Tallest Candles to be blown

Input Format
Array of Integers

Constraints

    \[1<candles[i]<10^7\]

Output Format
Count of Biggest Element in array

Sample Input

3 2 1 3 5 6 5 4 5

Sample Output

1
  1. In the above example 6 is the biggest element and it occurs only once
  2. Find the biggest element in array
  3. Find the count of the biggest element
public static int birthdayCakeCandles(List<Integer> candles) {
        // Write your code here
        long tallestCandle = 0;
        int tallestCandleCnt = 0;

        for(int num=0;num<candles.size();num++){
            if(tallestCandle<=candles.get(num)){
                tallestCandle = candles.get(num);
            }
        }

        for(int num=0;num<candles.size();num++){
            if(candles.get(num) == tallestCandle)
                tallestCandleCnt +=1;
        }

        return tallestCandleCnt;
    }

POST

 @Test
    void addEmployeeDetails() throws Exception {
        Employee objEmployee = (Employee) TestTraits.getObjfromJson("json-data/EmployeeObject.json");

        String jsonRequestString = mapper.writeValueAsString(objEmployee);

        when(employeeServiceImpl.saveEmployee(any())).thenReturn("101");

        ResultActions objResultActions = this.mockMvc.perform(post("/empmgmt/employees")
                .contentType(MediaType.APPLICATION_JSON)
                .content(jsonRequestString))
                .andDo(print())
                .andExpect(jsonPath("$.empID", is(Matchers.notNullValue())))
                .andExpect(jsonPath("$.empID", is(101)))
                .andExpect(jsonPath("$.empName", is("Mani")))
                .andExpect(status().isCreated());
    }

GET

 @Test
    void getEmployeeDetails() throws Exception {
        ClassLoader loader = Test.class.getClassLoader();
        Employee objEmployee = (Employee) TestTraits.getObjfromJson("json-data/EmployeeObject.json");

        Optional<Employee> objEmp = Optional.ofNullable(objEmployee);
        when(employeeServiceImpl.findEmployee(EMP_ID)).thenReturn(objEmp);

        ResultActions objResultActions = this.mockMvc.perform(get("/empmgmt/employees/{empID}",EMP_ID))
                                                    .andDo(print())
                                                    .andExpect(jsonPath("$.empID", is(101)))
                                                    .andExpect(jsonPath("$.empName", is("Mani")))
                                                    .andExpect(jsonPath("$._links.all-employees.href", is("http://localhost/empmgmt/employees")))
                                                    .andExpect(status().isOk());
    }

DELETE

 @Test
    void deleteEmployeeDetails() throws Exception {
        when(employeeServiceImpl.deleteEmployee(Long.valueOf(EMP_ID))).thenReturn(true);

        this.mockMvc.perform(delete("/empmgmt/employees/{empID}",EMP_ID))
                .andDo(print())
                .andExpect(content().string(containsString("Employee Deleted Successfully")))
                .andExpect(status().isOk());
    }

EmployeeControllerTest.java

package com.mugil.org.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mugil.org.TestTraits;
import com.mugil.org.models.Employee;
import com.mugil.org.services.EmployeeServiceImpl;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@ExtendWith(SpringExtension.class)
@WebMvcTest(EmployeeController.class)
class EmployeeControllerTest {

    @MockBean
    EmployeeServiceImpl employeeServiceImpl;

    ObjectMapper mapper = new ObjectMapper();

    @Autowired
    private MockMvc mockMvc;

    private static final String EMP_ID = "101";

    @Test
    void getEmployeeDetails() throws Exception {
        ClassLoader loader = Test.class.getClassLoader();
        Employee objEmployee = (Employee) TestTraits.getObjfromJson("json-data/EmployeeObject.json");

        Optional<Employee> objEmp = Optional.ofNullable(objEmployee);
        when(employeeServiceImpl.findEmployee(EMP_ID)).thenReturn(objEmp);

        ResultActions objResultActions = this.mockMvc.perform(get("/empmgmt/employees/{empID}",EMP_ID))
                                                    .andDo(print())
                                                    .andExpect(jsonPath("$.empID", is(101)))
                                                    .andExpect(jsonPath("$.empName", is("Mani")))
                                                    .andExpect(jsonPath("$._links.all-employees.href", is("http://localhost/empmgmt/employees")))
                                                    .andExpect(status().isOk());
    }

    @Test
    void deleteEmployeeDetails() throws Exception {
        when(employeeServiceImpl.deleteEmployee(Long.valueOf(EMP_ID))).thenReturn(true);

        this.mockMvc.perform(delete("/empmgmt/employees/{empID}",EMP_ID))
                .andDo(print())
                .andExpect(content().string(containsString("Employee Deleted Successfully")))
                .andExpect(status().isOk());
    }

    @Test
    void getAllEmployeeDetails() throws Exception {
        List<Employee> arrEmployees = new ArrayList<>();
        arrEmployees.add(getEmployee());

        when(employeeServiceImpl.findAllEmployee()).thenReturn(arrEmployees);

        ResultActions objResultActions = this.mockMvc.perform(get("/empmgmt/employees")
                .contentType(MediaType.APPLICATION_JSON))
                .andDo(print())
                .andExpect(jsonPath("$[0].empID", is(Matchers.notNullValue())))
                .andExpect(jsonPath("$[0].empID", is(101)))
                .andExpect(jsonPath("$[0].empName", is("Shivaji")))
                .andExpect(status().is2xxSuccessful());
    }

    @Test
    void addEmployeeDetails() throws Exception {
        Employee objEmployee = (Employee) TestTraits.getObjfromJson("json-data/EmployeeObject.json");

        String jsonRequestString = mapper.writeValueAsString(objEmployee);

        when(employeeServiceImpl.saveEmployee(any())).thenReturn("101");

        ResultActions objResultActions = this.mockMvc.perform(post("/empmgmt/employees")
                .contentType(MediaType.APPLICATION_JSON)
                .content(jsonRequestString))
                .andDo(print())
                .andExpect(jsonPath("$.empID", is(Matchers.notNullValue())))
                .andExpect(jsonPath("$.empID", is(101)))
                .andExpect(jsonPath("$.empName", is("Mani")))
                .andExpect(status().isCreated());
    }

    private Employee getEmployee(){
        Employee objEmployee = new Employee();

        objEmployee.setEmpID(Long.valueOf(101));
        objEmployee.setEmpAge("35");
        objEmployee.setEmpName("Shivaji");

        return objEmployee;
    }
}

TestTraits.java

package com.mugil.org;

import com.google.gson.Gson;
import com.mugil.org.models.Employee;
import org.springframework.core.io.ClassPathResource;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public interface TestTraits {
    public static Object getObjfromJson(String fileLoctaion) throws IOException {
        Gson gson = new Gson();
        Employee objEmployee2 = gson.fromJson(getReader(fileLoctaion), Employee.class);
        return objEmployee2;
    }

    public static Reader getReader(String fileLoctaion) throws IOException {
        return new FileReader(new ClassPathResource(fileLoctaion).getFile());
    }
}

EmployeeObject.json

{
  "empID": 101,
  "empName": "Mani",
  "empAge": "35"
}

EmployeeControllerTest.java
Read JSON Value as from File and Convert to Employee Object and to JSON String

JSON Value from File -> Employee Object -> JSON String from Object

  @Test
    void addEmployeeDetails() throws Exception {
        
        //Read values from JSON  
        Employee objEmployee = (Employee) TestTraits.getObjfromJson("json-data/EmployeeObject.json");

        //Convert Object to JSON String
        String jsonRequestString = mapper.writeValueAsString(objEmployee);

        when(employeeServiceImpl.saveEmployee(any())).thenReturn("101");

        ResultActions objResultActions = this.mockMvc.perform(post("/empmgmt/employees")
                .contentType(MediaType.APPLICATION_JSON)
                .content(jsonRequestString))
                .andDo(print())
                .andExpect(jsonPath("$.empID", is(Matchers.notNullValue())))
                .andExpect(jsonPath("$.empID", is(101)))
                .andExpect(jsonPath("$.empName", is("Mani")))
                .andExpect(status().isCreated());
    }

EmployeeControllerTest.java
Read JSON Value as from File and Convert to Employee Object and to JSON String

JSON Value from File -> Employee Object for Mocking Service Call


@Test
    void getEmployeeDetails() throws Exception {
          
        //Object Construction by reading file
        Employee objEmployee = (Employee) TestTraits.getObjfromJson("json-data/EmployeeObject.json");

        //Making object as Optional
        Optional<Employee> objEmp = Optional.ofNullable(objEmployee);

        //Mocked service response from object created
        when(employeeServiceImpl.findEmployee(EMP_ID)).thenReturn(objEmp);

        ResultActions objResultActions = this.mockMvc.perform(get("/empmgmt/employees/{empID}",EMP_ID))
                                                    .andDo(print())
                                                    .andExpect(jsonPath("$.empID", is(101)))
                                                    .andExpect(jsonPath("$.empName", is("Mani")))
                                                    .andExpect(jsonPath("$._links.all-employees.href", is("http://localhost/empmgmt/employees")))
                                                    .andExpect(status().isOk());
    }

Repo Link
https://bitbucket.org/Mugil/restwithspringboot/branch/feature/7MockMVCTesting_3

## Summary

Below are the List of Features available in Code

1. Reading payload from JSON File and using it as mocked Response
2. Object creation from JSON File
---

## Things Newly Implemented

1. JSON Payload files are found in src/test/resources/json-data
2. In the Code Converstion to Employee Object after reading Employee JSON and Stringify of JSON Object are both done  
3. MockMvc Testing is implemented for Controllers	
	- For AddEmployee Endpoint - Request from JSON file, Response from mocked response  
	- For GetEmployee Endpoint - Request by URL, Response from mocked Employee object constructed from JSON File
	- For GetAllEmployees Endpoint - Request by URL, Response from method returning Employee Object
	- For DeleteEmployee Endpoint - Request by URL, Response from mocked method	 	  
---

## Changes in pom.xml 
```xml
<build>
    <testResources>
        <testResource>
            <directory>${project.basedir}/src/test/resources</directory>
        </testResource>			
    </testResources>
    .
    .
    .
</build>
```
---

# API endpoints
## GET
`Get All Employees Detail` [/empmgmt/employees](#getallemployee) <br/>
`Get Employee Details` [/empmgmt/employees/{empId}](#getemployeesempid) <br/>

## POST
`Add Employee Details` [/empmgmt/employees](#addemployee) <br/>

## DELETE
`Delete EmpDetails` [/empmgmt/employees/{empId}](#deleteemployee) <br/>
___

<a name="getemployeesempid"></a>
### GET /empmgmt/employees/{empId}
Get Employee Detail

**Parameters**

|          Name | Required |  Type   | Description                                                                                                                                                           |
| -------------:|:--------:|:-------:| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|     `empId` | required | string  | Employee Id

**Response**

```
// Employee Details added Succesfully
[
    {
        "empID": 1,
        "empName": "Mugil",
        "empAge": "36"
    }
]
```
___

<a name="getallemployee"></a>
### GET /empmgmt/employees

**Response**
```
// Employee Details added Succesfully
[
    {
        "empID": 1,
        "empName": "Mugil",
        "empAge": "36"
    }
]
```
___

<a name="addemployee"></a>
### POST /empmgmt/employees
Add Employee Details

**Parameters**

|          Name | Required |  Type   | Description                                                                                                                                                           |
| -------------:|:--------:|:-------:| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|     `empName` | required | string  | Name of Employee
|     `empAge` | required | string  | Age of Employee

**Request**
```
// Employee Details 
{
    "empName" : "Mugil",
    "empAge" : "36"
}
```


**Response**

```
// Employee Details added Succesfully
[
    {
        "empID": 1,
        "empName": "Mugil",
        "empAge": "36"
    }
]
```
___

<a name="deleteemployee"></a>
### DELETE /empmgmt/employees/{empId}

**Parameters**

|          Name | Required |  Type   | Description                                                                                                                                                           |
| -------------:|:--------:|:-------:| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|     `empId` | required | string  | Employee Id


**Response**

```
Employee Deleted Successfully
```
___



## Note

* While reading file from resources folder I continously got error telling the file doesnot exists. 
  The Same problem is faced while working in office project. After adding above lines in pom.xml it started 
  working. It kept working, even after removing above lines
* The URL returned in _Link in add employee wont have a port number. The test keeps failing if you copy and paste
  URL from postman and try to asset the _links in mockMVC

___    

Copy paste the code in URL to see in action : https://markdownlivepreview.com/

Readme file screen shot for above code

Icebreaker Session : An ice breaker is an activity, game, or event that is used to welcome and warm up the conversation among participants in a meeting.

Activity 1: Form Small Teams and ask them to discuss one common interest among group members. They would talk within themself and end up in one common interest. This should be done within 60 Seconds.

Again the same process is repeated for 60 seconds by combining team together and finding their common interest.

I.E. Suppose there are 30 people in the room and we are dividing 5 teams with 6 members in each team we would come up with common interest for 6 members in team in the first 60 seconds and we would come up with common interest for 12 members after combining team in the second 60 seconds.

Common interests could be anything like food, sports, going for a walk, dislikes, or horror movies.

At the end of 60 seconds, one team member should let others know what is the common thing is shared by the team members.

Activity 2: Ask the client about them and one secret.

Crowd Storming: Crowdstorming is a massive collaborative brainstorming session with a large community of people. With crowd storming, you tap into ideation—or the collection of ideas from a group of people—and leverage it to solve a specific issue.

Activity 1: Take sticky notes and ask the 30 members in the room to write an idea in a few words. The idea could be anything I.E Openness and collaboration, 4Hr work week, Team Outing, Pair Programming, Regular connect with clients. You would give 30 seconds to think so the members would write their ideas on a sticky note with their names on top. Once they are done we would play music and make them take walk in the room.

Once the music is paused we would hand over the sticky notes to a random person who is next to them and ask for a rating. The other person reads the idea and writes the rating on a sticky note and hands it back to the person to whom it belongs to and vice versa. The rating could be 1 to 5. The same process is repeated by playing and pausing music three times and getting their ideas rated thrice by three different persons.

Now all the 3 ratings from 3 individuals would be summed. The crowd storming boards would have 3 sections.

<----------1-5--------->|<----------5-10--------->|<----------11-15--------->
                        |                         |                 
                        |                         |        
                        |                         |                          
                        |                         |          

Collect all the sticky notes and post it in the appropriate section. The Stickies in sections 11-15 could be collected and ideas could be discussed and elaborated with the members who wrote in as a group in the room.

Back to Back Drawing : You would make the team members stand in line and the last person to pick a chit from a lot that has simple drawings. The last person in the group should guide the before one by drawing at their back. This continues till the first person draws the figure on board.

While doing this using paper and a marker to draw would be effective. Try to get Plastic Sheets that could be used to place the paper while drawing on someone’s back since using markers on someone’s back may end up with creases or strains in their shirts. The drawing in chit should be simple shapes and not complex ones.

Below are a few drawings that could be used.

Chinese whispers Make people standin line. The message should be read by last person and communicated to the before person in action. It should be simple phrases from things around them in the room. I.E Temperature is hot, I dont know, Salt and pepper, Its Sunny outside. The first person in the line should come back to the last person and convey what he understood.

Other Things to be checked before Client Arrival:

  1. WiFi – Check whether the wifi is connecting and available to them in your mobile before they arrive
  2. Check the TV connectivity for conference call incase needed. Also do dry run if possible with some one at onsite
  3. Availability of water bottles in Room.
  4. Room Temperature and AC
  5. Some mild music which could be played when they enter the room

Casual Conversation Questions to Ask

  • How is your flight
  • How do you like the city

பொதுவாக ஜோதிடப்படி, ராகுகாலம், எமகண்டத்தில் எந்தவொரு நல்ல செயலை செய்யமாட்டார்கள். ஆனால், குளிகை நேரத்தில் செய்யப்படும் எந்த காரியமும் திரும்பத் திரும்ப நடக்கும். ஆகையால், நல்ல காரியங்களுக்கு குளிகை நேரம் உகந்ததாகவும், ஈமச்சடங்கு போன்ற கெட்ட காரியங்களுக்கு குளிகை நேரம் பொருத்தமில்லாததாகவும் கருதப்படுகிறது. குளிகை நேரத்தில் ஒரு காரியத்தை தொடங்கினால், அது வளர்ந்துக்கொண்டே இருக்கும்.

குளிகையில் என்ன செய்யலாம்?

  • குளிகை நேரத்தில் சொத்து வாங்குவது
  • சுப நிகழ்வுகள்
  • கடனை திருப்பி கொடுப்பது
  • பிறந்தநாள் கொண்டாடுவது

போன்றவற்றை செய்வதால் அச்செயல்கள் எந்த தடையும் இல்லாமல் நடப்பது மட்டுமின்றி, இதுபோன்ற நல்ல நிகழ்ச்சிகள் தொடர்ந்து நடந்து கொண்டும் இருக்கும்.

குளிகையில் என்ன செய்யக்கூடாது?

  • அடகுவைப்பது
  • கடன் வாங்குவது
  • வீட்டை காலிசெய்வது
  • இறந்தவர் உடலை கொண்டு செல்வது
  • போன்ற விஷயங்களை குளிகை நேரத்தில் செய்யக்கூடாது.

நல்ல காரியங்களை செய்வதற்கு உகந்த குளிகை நேரத்திற்குரிய குளிகனின் பிறப்பே ஒரு நல்ல நிகழ்வை தொடங்குவதற்காகத்தான் உருவானது.

குளிகன் உருவான கதை :

ராவணனின் மனைவி மண்டோதரி, கருவுற்று நிறைமாத கர்ப்பிணியாக இருந்தார். ராவணன் தனது குல குருவான சுக்கிராச்சாரியாரை சந்தித்து, எப்போது வேண்டுமானாலும் குழந்தை பிறக்கும் நிலையில் உள்ளது என்றும், யாராலும் வெல்ல முடியாத, அழகும், அறிவும் கொண்ட மகனே தனக்கு பிறக்க வேண்டும் என்றும், அதற்கு என்ன வழி என்றும் கேட்டார்.அதற்கு பதில் அளித்த சுக்கிராச்சாரியார், கிரகங்கள் அனைத்தும் ஒரே கட்டத்தில் இருக்கும் நேரத்தில் உனக்கு குழந்தை பிறந்தால், அந்த குழந்தை நீ விரும்பிய எல்லா சிறப்புகளும் கொண்டதாக இருக்கும் என்று யோசனை சொன்னார். உடனே, நவகிரகங்கள் அனைத்தையும் சிறைப்பிடித்து, ஒரே அறைக்குள் அடைத்துவிட்டார் ராவணன். ஒரே அறையில் இருந்த கிரகங்கள் யாவும் தவித்துப் போயினர். இந்த யோசனையை சொன்ன சுக்கிராச்சாரியாரை கடிந்து கொண்டனர். ஒரே இடத்தில் இருப்பதால் நடக்கப்போகும் தீமைகளை எண்ணி கவலை கொண்டனர்.

இதேநேரத்தில் குழந்தை பிறக்க முடியாமல் மண்டோதரி பெரும் தவிப்பில் கிடந்தார். வலி அதிகம் இருந்தபோதிலும் குழந்தை பிறக்கவே இல்லை. இந்த செய்தி நவகிரகங்களின் காதிற்கு எட்டியதும், அதற்கும் தாங்கள்தான் காரணம் என்று ராவணன் தண்டிப்பாரோ என்று அச்சம் கொண்டனர். இது குறித்து சுக்கிராச்சாரியாரிடம் ஆலோசனை கேட்டனர். இந்த சிக்கலில் இருந்து விடுபட வேண்டுமானால், உங்கள் ஒன்பது பேரை தவிர, நல்ல செயல் புரிவதற்கென்று இன்னொரு புதியவனை சிருஷ்டித்து, ஒவ்வொரு நாளிலும் ஒரு குறிப்பிட்ட நேரத்தை அவனுடைய ஆளுகைக்கு உட்பட்ட நேரமாக மாற்றிக் கொடுத்தால், உங்களுக்கு நன்மை உண்டாகும் என்றார்.

அவனை சிருஷ்டிக்கும் அதேவேளையிலேயே மண்டோதரிக்கு சுகப்பிரசவம் உண்டாகும். நீங்களும் விடுதலை ஆகலாம் என்றார். அதன்படி சனீஸ்வர பகவான் சிறையில் இருந்தபடியே தனது சக்தியால் ஜேஷ்டாதேவிக்கு ஒரு மகன் பிறக்க வழிசெய்தார். குளிகன் பிறந்த அதேநேரம் மண்டோதரிக்கும் அழகான ஒரு மகன் பிறந்தான். அவனுக்கு மேகநாதன் என்று பெயர் சூட்டினர்.தான் பிறக்கும்போதே நல்லதை நடத்தி வைத்ததால், குளிகன் நவகிரகங்களால் பாராட்டப்பட்டார். குளிகை நேரம் என்றே தினமும் பகலிலும், இரவிலும் ஒரு நாழிகை நேரம் கொடுக்கப்பட்டது. அந்த நேரம், காரிய விருத்தி நேரம் என ஆசீர்வதிக்கப்பட்டது. இதனாலேயே குளிகை நேரத்தில் செய்யப்படும் எந்த ஒரு நல்ல காரியமும் தொடர்ந்து நடைபெறும் என்று கூறப்பட்டது.

In the below code there might arise a question why we need to do hashing and extract the final secret key from it. The importance of this step could be felt incase we are storing passwords in DBs instead of directly using actual secret key and hashing, the hashing by using message digest adds more strength.

EncryptUtil.java

package com.mugil.org;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;

public class EncryptUtil {
    private static SecretKeySpec secretKey;
    private static byte[] key;

    public static void setKey(String myKey) {
        MessageDigest sha = null;
        try {
            //Byte Arrays are secured compared to storing in String as it is immutable
            key = myKey.getBytes("UTF-8");

            /*
              MessageDigest class represents a cryptographic hash function which can calculate a
              message digest from binary data.A hash function is a mathematical function that 
              converts a numerical input value into another compressed numerical value.The input to 
              the hash function is of arbitrary length but output is always of fixed length.
              Values returned by a hash function are called message digest or simply hash values.
            */

            /*
              Code will work without below two lines but hashing adds more strength to secret key
              AES needs a 128/192/256 bits key. If you don't hash your key and only trim the input it
              would only use the first 16/24/32 Bytes. So generating a Hash is the only reasonable way.
             */
            sha = MessageDigest.getInstance("SHA-1");
            key = sha.digest(key);

            /*Use SHA-1 to generate a hash from your key and trim the result to 128 bit (16 bytes).*/
            key = Arrays.copyOf(key, 16);

            /*Taking Key that would be used for Encrytion */
            secretKey = new SecretKeySpec(key, "AES");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static String encrypt(String strToEncrypt, String secret) {
        try {
            setKey(secret);
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
            return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8")));
        } catch (Exception e) {
            System.out.println("Error while encrypting: " + e.toString());
        }
        return null;
    }

    public static String decrypt(String strToDecrypt, String secret) {
        try {
            setKey(secret);
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt)));
        } catch (Exception e) {
            System.out.println("Error while decrypting: " + e.toString());
        }
        return null;
    }
}

SimpleEncryption.java

package com.mugil.org;

public class SimpleEncryption {
    public static void main(String[] args) {
        final String secretKey = "ItSecretKey";

        String originalString = "You Nailed It!!!";
        String encryptedString = EncryptUtil.encrypt(originalString, secretKey) ;
        String decryptedString = EncryptUtil.decrypt(encryptedString, secretKey) ;

        System.out.println(originalString);
        System.out.println(encryptedString);
        System.out.println(decryptedString);
    }
}

You Nailed It!!!
lFY4a0e0BRVfcfko56Lpe78iUfPoZm5wkq/zv0hrFco=
You Nailed It!!!
  1. What is a Cipher?
    A cipher transforms data by processing the original, plaintext characters (or other data) into ciphertext, which should appear to be random data
  2. What is Message Digest? Why we need Message Digest?
    A message digest is a cryptographic hash function containing a string of digits created by a one-way hashing formula. Message digests are designed to protect the integrity of a piece of data or media to detect changes and alterations to any part of a message.This term is also known as a hash value and sometimes as a checksum.Message digests are encrypted with private keys creating a digital signature. This results in a type of validation ensuring that the appropriate user is accessing protected information. Message digests protect one-way hash algorithms taking random data and transmitting a set length hash value.
  3. What is role of Hasing in Security? Hashing helps in preventing or analyzing file tampering. The original data will generate a hash which is kept with the data. The data and the hash are sent together, and the receiving party checks that hash to see if the data has been compromised. If there were any changes to the data, the hash wont match.
  4. What is Secure Hash Algorithm (SHA)?Secure Hash Algorithms, also known as SHA, are a family of cryptographic functions designed to keep data secured. It works by transforming the data using a hash function: an algorithm that consists of bitwise operations, modular additions, and compression functions. The hash function then produces a fixed-size string that looks nothing like the original. These algorithms are designed to be one-way functions, meaning that once they’re transformed into their respective hash values, it’s virtually impossible to transform them back into the original data. A few algorithms of interest are SHA-1, SHA-2, and SHA-3, each of which was successively designed with increasingly stronger encryption in response to hacker attacks. SHA-0, for instance, is now obsolete due to the widely exposed vulnerabilities.
  5. What does MessageDigest getInstance() does?

    MessageDigest class provides a method named getInstance(). This method accepts a String variable specifying the name of the algorithm to be used and returns a MessageDigest object implementing the specified algorithm.Create MessageDigest object using the getInstance() method as shown below.

    MessageDigest md = MessageDigest.getInstance("SHA-256");
    

    After creating the message digest object, you need to pass the message/data to it. You can do so using the update() method of the MessageDigest class, this method accepts a byte array representing the message and adds/passes it to the above created MessageDigest object.

    md.update(msg.getBytes());
    

    You can generate the message digest using the digest() method od the MessageDigest class this method computes the hash function on the current object and returns the message digest in the form of byte array.Generate the message digest using the digest method.

    byte[] digest = md.digest();
    
  6. Could I use Public and Private Keys Inversely?
    Yes. The keys work inversely to each other. Encrypted something with your public key? Decrypt it with your private key. Conversely, if you encrypt something with your private key, you decrypt it with your public. Such is the nature of asymmetric cryptography.
  7. What is Symmetric and Asymmetric Keys?
    Symmetric just means that the same key is used to encrypt/decrypt. Asymmetric means that one key encrypts and a different key decrypts (and that the reverse is also true).

    #Creating a key Pair
    openssl genrsa -out private.pem 1024
    openssl rsa -in private.pem -out public.pem -pubout
    
    #Encrypt with public & decrypt with private
    openssl rsautl -encrypt -inkey public.pem -pubin -in message.txt -out message.ssl
    openssl rsautl -decrypt -inkey private.pem       -in message.ssl -out message.txt
    
    #Encrypt with private & decrypt with public
    openssl rsautl -sign    -inkey private.pem -in message.txt          -out message_enc_priv.ssl
    openssl rsautl -inkey public.pem -pubin    -in message_enc_priv.ssl -out message_priv.txt
    
  8. In the above example, you could see the public key is genarated first followed by generation of private key. Any idea why it is so?
    elliptic curve cryptography (also called “elliptic curve multiplication”) is the answer to the question. Elliptic curve cryptography is the mathematical relationship that makes the following conditions possible:

    • A public key can be mathematically generated from a private key
    • A private key cannot be mathematically generated from a public key (i.e. “trapdoor function”)
    • A private key can be verified by a public key

    a public/private keypair is created using elliptic curve cryptography, which by nature, creates a public and private key that are mathematically linked in both directions, but not mathematically derived in both directions.

  9. is JWT secured?
    JWT are used for authorization and not authentication.Information in the payload of the JWT is visible to everyone. There can be a “Man in the Middle” attack and the contents of the JWT can be changed. So we should not pass any sensitive information like passwords in the payload. We can encrypt the payload data if we want to make it more secure. If Payload is tampered with server will recognize it.
  10. What is Resource and Authorization Server? Authorization server is the one which issues the JWT after authentication. Resource server is the one which authorizes User every time using JWT while accesing resource
  11. What does .pem file contains?
    PEM stands for Privacy-Enhanced Mail. A PEM file may contain anything including a public key, a private key, or both, because a PEM file is not a standard. In effect PEM just means the file contains a base64-encoded bit of data.
    Typically a PEM file contains a base64 encoded key or certificate with header and footer lines of the form —–BEGIN —– and —–END —-. Over time there have evolved many possibilities for , including private keys, public keys, X509 certificates, PKCS7 data, files containing multiple certificates, files containing both the private key and the X509 certificate.
  12. What is CSR and CRT(or)CER?
    Certificate Signing Request contains information such as the public key and common name required by a Certificate Authority to create and sign a certificate for the requester, the encoding could be PEM or DER. These get signed by the CA and a certificate is returned. The returned certificate is the public certificate (which includes the public key but not the private key). Since the public key is signed by CA, the CA is confident the one who has sent for signing is the only one who has access to private key.
  13. What is PKIX?
    PKIX is an IETF (Internet Engineering Task Force) working group with the goal of supporting public key infrastructures based on X.509 on the Internet.X.509 certificate is a digital certificate based on the widely accepted International Telecommunications Union (ITU) X.509 standard, which defines the format of public key infrastructure (PKI) certificates. They are used to manage identity and security in internet communications and computer networking

In JWT both Header and Payload is encoded to make it URL Safe but not encrypted. So any one can see the content after decoding the Header and Payload. We cannot send any sensitive data using JWT.The signature is created using the header, the payload, and the secret that is saved on the server.

   Signature = Header + Payload + Secret

The above process is Signing the JSON Web Token. The signing algorithm takes the header, the payload, and the secret to creating a unique signature. So only this data plus the secret can create this signature. Together with the header and the payload, these signature forms the JWT, which then gets sent to the client.

Once the server receives a JWT to grant access to a protected route, it needs to verify it in order to determine if the user really is who he claims to be. In other words, it will verify if no one changed the header and the payload data of the token. So again, this verification step will check if no third party actually altered either the header or the payload of the JSON Web Token.

The signature is an HMAC, which uses a particular type of cryptographic function. Such an HMAC algorithm is indicated with the “HS” prefix, as shown in the sample token above. The HMAC takes the header, the payload, and a secret key as input, and returns a unique signature over all three inputs. Service uses the same secret key to calculate the HMAC of the JWT. If the resulting HMAC is the same as the signature in the token, the service knows that all three inputs to the HMAC function were the same as before.

{
   "typ":"JWT",
   "alg":"HS256"
}

How Verification is Carried to check whether payload has been changed?

Once the JWT is received, the verification will take its header and payload, and together with the secret that is still saved on the server, basically create a test signature.

The original signature that was generated when the JWT was first created is still in the token which is the key to this verification. We have to compare the test signature with the original signature. And if the test signature is the same as the original signature, then it means that the payload and the header have not been modified. If they had been modified, then the test signature would have to be different. Therefore in this case where there has been no alteration of the data, we can then authenticate the user. And of course, if the two signatures are actually different, well, then it means that someone tampered with the data. Usually by trying to change the payload. Third party manipulating the payload does not have access to the secret(Private key used to sign), so they cannot sign the JWT. So the original signature will never correspond to the manipulated data. And therefore, the verification will always fail in this case.

Limitations of Symmetric Signatures
This signature scheme is straightforward. It is also the typical scheme used to explain JWTs to developers. Unfortunately, symmetric signatures prevent the sharing of the JWT with another service. To verify the JWT’s integrity, all services would need to have access to the same secret key. However, possession of the secret key is enough to generate arbitrary JWTs with a valid signature.

Sharing the HMAC secret with a third-party service creates a significant vulnerability. Even sharing the secret between different services within a single architecture is not recommended. If all services share the same key, the compromise of a single service immediately becomes an architecture-wide problem.

Instead of sharing the secret HMAC key, you can opt for using asymmetric signatures

Note: The above could be helpful of the Authorization Server and Resource Server is same.

Link to Repo

Posted in JWT.