Simple PHP encrypt and decrypt

You need to have openssl encrypt installed and running. Check this thread if you dont have it already
http://stackoverflow.com/questions/11525524/why-cant-i-use-openssl-encrypt

/**
 * simple method to encrypt or decrypt a plain text string
 * initialization vector(IV) has to be the same when encrypting and decrypting
 * PHP 5.4.9 ( check your PHP version for function definition changes )
 *
 * this is a beginners template for simple encryption decryption
 * before using this in production environments, please read about encryption
 * use at your own risk
 *
 * @param string $action: can be 'encrypt' or 'decrypt'
 * @param string $string: string to encrypt or decrypt
 *
 * @return string
 */
function encrypt_decrypt($action, $string) {
    $output = false;

    $encrypt_method = "AES-256-CBC";
    $secret_key = 'This is my secret key';
    $secret_iv = 'This is my secret iv';

    // hash
    $key = hash('sha256', $secret_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 = "This is my plain text";
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";

Microsoft Outlook 2013 hangs at “Loading Profile…” after Office Update

Now here’s an interesting conundrum.  A recent update to Microsoft Office 2013 that’s being pushed out automatically to clients results in some of them being unable to open Outlook 2013.  Instead of running normally, the program will hang at the “Loading Profile” stage of launch, as though the profile is corrupt (if you haven’t already checked this, it could actually be the case instead of course).  A workaround is to open Outlook using the well-known /safe command line switch; but this is merely a workaround (which in turn disables all add-ons), not a permanent solution.

For a much more reasonable resolution, try this instead:

  1. Run regedit (Start > Run > type regedit and press ENTER)
    1. On Windows 8, Win + R; type regedit and press ENTER
  2. Navigate to HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Common
  3. Right-click, select New > Key and name it Graphics
  4. Select the Graphics key you just created, right-click in the right panel and chooseNew > DWORD (32-bit) Value and name it DisableHardwareAcceleration.
  5. Double-click the new value and assign it a value of 1.
  6. Close regedit and try opening Outlook again.

This should fix the problem.  I first stumbled upon the solution when I realized that opening my TeamViewer Remote Support program while Outlook was loading kicked it into launching, which suggested either a network- or graphics-related cause (as TV affects both of those when launching).  The original solution listed here came from the Microsoft Office 2013 Issues Blog, though the symptoms listed are different from these.

Hope this helps! 🙂

Cisco ASA – How to View pre-shared keys in plain text

As engineers, you don’t always document things as well as we should OR someone you work with is always “too busy” to document their work. This little trick will show you how to recover pre-shared keys on a Cisco Pix or ASA firewall.

Normally, you use the ’show run’ command to view the running configuration. Pre-shared keys are marked with an asterisk (*). To view the password unencrypted, type ‘more system:running-config’. This will display the full configuration with unencrypted passwords.

To bad actually that the pre-shared key of an Cisco VPN Client doesn’t show up in the latest ASA software version 8.2.2. the pre-shared keys of the VPN Tunnels are showed.

How to delete stuck snapshot from FreeNAS

When you’re trying to delete a snapshot from the FreeNAS you receive a message cannot destroy snapshot backups@auto-20140315.1448-2d: dataset is busy. 

This may be caused by stuck replication job is preventing the snapshot from being deleted.

Run the following command to see what is being held.

 zfs holds Data@auto-20141107.1513-4w
NAME                        TAG           TIMESTAMP
Data@auto-20141107.1513-4w  freenas:repl  Fri Nov  7 15:16 2014

You can then release the stuck snapshot.

[root@NAS] ~# zfs release -r freenas:repl Data@auto-20141107.1513-4w

Then you are able to delete the snapshot.

[root@NAS] ~# zfs destroy -r Data@auto-20141107.1513-4w

How to enable auto login for Windows 7

Problem

After a workstation is added to an Active Directory domain you are unable to set the computer to automatically logon using the control userpasswords2 (User Accounts) tool.

When you open the tool you find the ‘Users must enter a user name and password to use this computer’ option is missing.

MSWindows7-AutoLogonDomain

Solution

NOTE: Passwords for domain accounts typically expire and are changed regularly. If the password for the domain account changes you will need to update the settings in the registry.

You will need to configure the automatic logon through the registry editor.

  1. Open the registry editor (regedit)
  2. Navigiate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
  3. Open the ‘AutoAdminLogon’ key and change it’s value to “1”
  4. MSWindows7-AutoLogonDomain2
  5. Open the ‘DefaultDomainName’ key and set the value to your domain name (or the computers name if using a local account)
  6. Open the ‘DefaultUserName’ key and set the value to the user name for the auto logon
  7. Create a new STRING (REG_SZ) value called ‘DefaultPassword’ and set the value to the user account password.

NOTE:

If you’re unsure what the ‘DefaultDomainName’ field needs, you can open the command prompt (Windows + R, enter cmd and hit enter) and enter

echo %userdomain%

If you’re unsure what the ‘DefaultUserName’ field needs, you can open the command prompt (Windows + R, enter cmd and hit enter) and enter

echo %username%

The output (in this case “DEV” needs to be the same as the ‘DefaultDomainName’ value as indicated in the picture below).

MSWindows7-AutoLogonDomain3

Error: word couldn’t start last time. safe mode could help you troubleshoot the problem

When you start any MS Office 2013 software, you receive a message telling you that you need to start in safe mode. “Word couldn’t start last time. safe mode could help you troubleshoot the problem”.

Disable hardware acceleration (This fixed MY problem!)

1. Run regedit (Win + R ; “regedit“)
2. Browse to HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Common
3. Create a New Key and name it “Graphics
4. Select Graphics, right-click on the right panel and create a New DWORD (32-bit) Value and name it DisableHardwareAcceleration.
5. Enter Value data as 1
Try to run Excel normally now.

 

Error: The VPN client agent was unable to create the interprocess communication depot.

When attempting to install the Cisco AnyConnect client for UI Anywhere access, you receive the following error message:

The VPN client agent was unable to create the interprocess communication depot.

To resolve this issue:

  1. Click the Start button.
  2. Click on Control Panel.
  3. Click on View Network Status and Tasks.
  4. Click on Change Adapter Settings.
  5. Right-click the shared connection and choose Properties
  6. Click the Sharing tab
  7. Clear the Allow other network users to connect through this computer’s Internet connection checkbox
  8. Click OK.