Search This Blog

Thursday, March 15, 2018

Ruby Rails Rest-Client with POST Parameters, Authorization, Headers

response = RestClient::Request.new({
      method: :post,
      url: 'https://infovijay.com,
      user: 'vijay',
      password: 'dr12345',
      payload: { key1: 'value1', key2: 'value2' },
      headers: { :accept => :json, content_type: :json }
    }).execute do |response, request, result|
      case response.code
      when 400
        [ :error, parse_json(response.to_str) ]
      when 200
        [ :success, parse_json(response.to_str) ]
      else
        fail "#{response.to_str}."
      end
    end

Thursday, March 8, 2018

How to take from Custom/Local Lib - Maven

1. create a folder
2. in maven tag specify the local path
3.  what ever the jar you kept inside the folder. just add those jar in like how u r specifying normally.
4. Maven will pick in local repo, while compile or build [ whenever it perform ]





Wednesday, March 7, 2018

PHP - Aes-256-cbc Encrypt Decrypt with IV vector


function encrypt_decrypt($action, $string) {
    $output = false;
    $encrypt_method = "aes-256-cbc";
    $secret_key = 'abcdefghi1234567890';
    $secret_iv = '';
 
// hash
    $key = hash('sha256', $secret_key);
    echo "

".$key;

    // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
    $iv = substr(hash('sha256', $secret_iv), 0, 16);
    if ( $action == 'encrypt' ) {
        $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
        $output = base64_encode($output);
    } else if( $action == 'decrypt' ) {
        $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
    }
    return $output;
}
$plain_txt = "I am vijay";
echo "

Plain Text =" .$plain_txt. "\n";
$encrypted_txt = encrypt_decrypt('encrypt', $plain_txt);
echo "

Encrypted Text = " .$encrypted_txt. "\n";

$decrypted_txt = encrypt_decrypt('decrypt', $encrypted_txt);
echo "

Decrypted Text =" .$decrypted_txt. "\n";

if ( $plain_txt === $decrypted_txt ) echo "

SUCCESS";
else echo "

FAILED";
echo "\n";

?>



Output

Plain Text =I am vijay

681448fb66d8704c7d52f6770f6087882db21c899fe48d21012a587bbe70cdd3

Encrypted Text = THRtUkJYWFUzb1NzUFRoOUw5T3Q2UT09

681448fb66d8704c7d52f6770f6087882db21c899fe48d21012a587bbe70cdd3

Decrypted Text =I am vijay

SUCCESS

PHP - Encrypt / Decrypt with out IV Vector with AES-256-CBC



const PASSWORD = 'abcdefghi1234567890';
const CIPHER_METHOD = 'AES-256-CBC';

function encrypt($str) {
    $val = openssl_encrypt($str, CIPHER_METHOD, hash('sha256', PASSWORD, true));
    return $val;    
}

function decrypt($str) {
   return openssl_decrypt($str, CIPHER_METHOD, hash('sha256', PASSWORD, true));
}

$plain_data = 'I am vijay';

$encrypted = encrypt($plain_data);
echo "Encrypted : ".$encrypted."

";


$decrypted = decrypt($encrypted);
echo "Decrypted : ".$decrypted."

";


?>


Output

: openssl_encrypt(): Using an empty Initialization Vector (iv) is potentially insecure and not recommended in D:\php\test.php >

Encrypted :
zmuNrqZ+GwtQC5B0riJoMw==

Decrypted : I am vijay


Hit Counter


View My Stats