高度なカスタマイズ > ビジネスロジックのカスタマイズ > 暗号化されたパスワード > 暗号化されたパスワード > サンプルコード
  
サンプルコード
Windchill が値を暗号化するための Java キーストアの作成:
try
{
WTKeyStore keyStore = new
WTKeyStore(WTProperties.getLocalProperties(). getProperty("wt.home"));
}catch(IOException e){
logger.error("Could not load keystore", e);
}
キーストア内の値の暗号化:
String value = “encrypted.wt.pom.dbPassword”;
String property = “wt.pom.dbPassword”;
try
{
WTKeyStore keyStore = new
WTKeyStore(WTProperties.getLocalProperties(). getProperty("wt.home"));
// encrypt property value
keyStore.put(property, value);
} catch (IOException ioe) {
logger.error("Error creating keystore: ", ioe);
} catch (NullPointerException npe) {
logger.error("Could not add the encrypted value to the keystore: ", npe);
}
プロパティの解読:
String product_root = WTProperties.getLocalProperties(). getProperty(“wt.home”);
String value = “encrypted.wt.pom.dbPassword”;
String property = “wt.pom.dbPassword”;
// decrypt encrypted values
value = WTKeyStoreUtil.decryptProperty(property, value, product_root);
/* value can now be used as normal as it will contain the decrypted value */
値を解読するために使用できる第 2 の手段:
String value = “encrypted.wt.pom.dbPassword”;
try
{
WTKeyStore keyStore = new
WTKeyStore(WTProperties.getLocalProperties(). getProperty("wt.home"));
// decrypt encrypted values
String ks_value = keyStore.get(value);
if(ks_value != null)
{
value = ks_value;
}
}catch(IOException e){
logger.error("Could not load keystore", e);
}
動的プロパティを暗号化するための新しい正規表現の追加:
/* This code currently exists in WTKeystoreUtil.java. except where
* where denoted “NEW”
*/
private static final String NEW_REGULAR_EXPRESSION = “<your regular
expression goes here>”; // NEW

private static List<String> getEncryptionPropertiesRegExList(final
String product_root) {
List<String> propertiesList = new ArrayList<String>();

if(isCompletePropertiesListFile(product_root)) {
/*
* add a hardcoded list of dynamic properties that will
* utilize regular expressions to determine what to encrypt
* for dynamic property names.
*/
propertiesList.add(WT_FEDERATION_DEFAULTAUTHORIZATION);
propertiesList.add(NEW_REGULAR_EXPRESSION); // NEW
logger.debug("Full property list found, returning regex
list of size=" + propertiesList.size());
} else {
logger.debug("Full property list not found, return empty
regex list");
}
return propertiesList;
}
これにより、プロパティ名のパターンを検索するための新しい正規表現が追加されます。ここでも、正規表現を作成するときには、注意が必要です。手順 – .xconf が管理する単一値の動的プロパティの暗号化を参照してください。