Initial graduated contribution
diff --git a/bundles/org.eclipse.equinox.security.win32.x86/cpp/ReadMe.txt b/bundles/org.eclipse.equinox.security.win32.x86/cpp/ReadMe.txt
new file mode 100644
index 0000000..b5f137c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.win32.x86/cpp/ReadMe.txt
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+This is a JNI bridge to access native Windows encryption methods from Java. The methods
+perform user-specific encryption of the data. The same user can later decrypt data using
+methods provided by this DLL. A different user won't be able to decrypt the data.
+
+If the user has a roaming profile, he can decrypt data on a different computer in the domain.
+
+In the event if stand-alone computer needs to have OS re-installed (or the domain controller
+and the computer in the domain), be sure to create Windows password recovery disk BEFORE
+re-installing the operating system.
+
+Note that this mechanism is intended to be used with small size data (i.e., passwords). For
+large amount of data consider encrypting your password using this mechanism and using
+symmetric encryption to encrypt the data.
+
+To compile this DLL:
+=> JAVA_HOME environment variable needs to be setup so that jni.h can be found
+
+Note C++ projects settings:
+=> Additional include directories - "$(JAVA_HOME)/include";"$(JAVA_HOME)/include/win32"
+=> Additional linker dependency - Crypt32.lib
diff --git a/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.cpp b/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.cpp
new file mode 100644
index 0000000..9a8f2c4
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.cpp
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+
+#include <windows.h>
+#include <wincrypt.h>
+#include "jnicrypt.h"
+
+BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
+{
+ return TRUE;
+}
+
+JNIEXPORT jbyteArray JNICALL Java_org_eclipse_equinox_internal_security_win32_WinCrypto_winencrypt
+ (JNIEnv *env, jobject obj, jbyteArray value)
+{
+ jsize size = env->GetArrayLength(value);
+ jbyte *body = env->GetByteArrayElements(value, NULL);
+ if (body == NULL)
+ return NULL;
+
+ DATA_BLOB clearText;
+ DATA_BLOB encryptedText;
+ clearText.pbData = (BYTE*) body;
+ clearText.cbData = (DWORD) size;
+
+ BOOL result = CryptProtectData(&clearText, L"Equinox", NULL, NULL, NULL, 0, &encryptedText);
+
+ // release memory allocated by Java environment
+ env->ReleaseByteArrayElements(value, body, 0);
+
+ if (result == FALSE)
+ return NULL;
+
+ jbyteArray returnArray = env->NewByteArray(encryptedText.cbData);
+ env->SetByteArrayRegion(returnArray, 0, encryptedText.cbData, (jbyte*) encryptedText.pbData);
+ LocalFree(encryptedText.pbData); // no need any more, have Java representation
+
+ return returnArray;
+}
+
+JNIEXPORT jbyteArray JNICALL Java_org_eclipse_equinox_internal_security_win32_WinCrypto_windecrypt
+ (JNIEnv *env, jobject obj, jbyteArray value)
+{
+ jsize size = env->GetArrayLength(value);
+ jbyte *body = env->GetByteArrayElements(value, NULL);
+ if (body == NULL)
+ return NULL;
+
+ DATA_BLOB clearText;
+ DATA_BLOB encryptedText;
+ encryptedText.pbData = (BYTE*) body;
+ encryptedText.cbData = (DWORD) size;
+
+ LPWSTR pDescrOut = NULL;
+ BOOL result = CryptUnprotectData(&encryptedText, &pDescrOut, NULL, NULL, NULL, 0, &clearText);
+
+ if (pDescrOut != NULL)
+ LocalFree(pDescrOut);
+
+ // release memory allocated by Java environment
+ env->ReleaseByteArrayElements(value, body, 0);
+
+ if (result == FALSE)
+ return NULL;
+
+ jbyteArray returnArray = env->NewByteArray(clearText.cbData);
+ env->SetByteArrayRegion(returnArray, 0, clearText.cbData, (jbyte*) clearText.pbData);
+ LocalFree(clearText.pbData); // no need any more, have Java representation
+
+ return returnArray;
+}
diff --git a/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.h b/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.h
new file mode 100644
index 0000000..9d44ffe
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.h
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+#include <jni.h>
+
+#ifndef EQUINOX_WIN32_CRYPTO
+#define EQUINOX_WIN32_CRYPTO
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT jbyteArray JNICALL Java_org_eclipse_equinox_internal_security_win32_WinCrypto_windecrypt(JNIEnv *, jobject, jbyteArray);
+JNIEXPORT jbyteArray JNICALL Java_org_eclipse_equinox_internal_security_win32_WinCrypto_winencrypt(JNIEnv *, jobject, jbyteArray);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // #ifndef EQUINOX_WIN32_CRYPTO
+
diff --git a/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.vcproj b/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.vcproj
new file mode 100644
index 0000000..c207c57
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.win32.x86/cpp/jnicrypt.vcproj
@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="jnicrypt"
+ ProjectGUID="{F34C755E-2053-4783-85FC-356BC2CE2A35}"
+ RootNamespace="jnicrypt"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=""$(JAVA_HOME)/include";"$(JAVA_HOME)/include/win32""
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;JNICRYPT_EXPORTS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="Crypt32.lib"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""$(JAVA_HOME)/include";"$(JAVA_HOME)/include/win32""
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;JNICRYPT_EXPORTS"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="Crypt32.lib"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\jnicrypt.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\jnicrypt.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ <File
+ RelativePath=".\ReadMe.txt"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>