本文整理匯總了Java中java.util.prefs.Preferences.getByteArray方法的典型用法代碼示例。如果您正苦於以下問題:Java Preferences.getByteArray方法的具體用法?Java Preferences.getByteArray怎麽用?Java Preferences.getByteArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.prefs.Preferences
的用法示例。
在下文中一共展示了Preferences.getByteArray方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: call
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public Void call() throws Exception { // encryption changing
LOG.fine("encryption changing");
Map<String,char[]> saved = new HashMap<String,char[]>();
Preferences prefs = prefs();
for (String k : prefs.keys()) {
if (k.endsWith(DESCRIPTION)) {
continue;
}
byte[] ciphertext = prefs.getByteArray(k, null);
if (ciphertext == null) {
continue;
}
saved.put(k, encryption.decrypt(ciphertext));
}
LOG.log(Level.FINE, "reencrypting keys: {0}", saved.keySet());
encryption.encryptionChanged();
for (Map.Entry<String,char[]> entry : saved.entrySet()) {
prefs.putByteArray(entry.getKey(), encryption.encrypt(entry.getValue()));
}
LOG.fine("encryption changing finished");
return null;
}
示例2: getIconList
import java.util.prefs.Preferences; //導入方法依賴的package包/類
protected final List<ExtIcon> getIconList(String key, boolean allowGrouped) {
Preferences pref = getPreferences(allowGrouped);
int count = 0;
byte[] val = pref.getByteArray(key + "." + count, null);
List<ExtIcon> toRet = new ArrayList<ExtIcon>();
while (val != null) {
toRet.add(val.length > 0 ? new ExtIcon(val) : new ExtIcon());
count = count + 1;
val = pref.getByteArray(key + "." + count, null);
}
return toRet;
}
示例3: testSampleKey
import java.util.prefs.Preferences; //導入方法依賴的package包/類
private boolean testSampleKey(Preferences prefs) {
byte[] ciphertext = prefs.getByteArray(SAMPLE_KEY, null);
if (ciphertext == null) {
encryption.freshKeyring(true);
byte[] randomArray = new byte[36];
new SecureRandom().nextBytes(randomArray);
if (_save(SAMPLE_KEY, (SAMPLE_KEY + new String(randomArray)).toCharArray(),
NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.sample_key.description"))) {
LOG.fine("saved sample key");
return true;
} else {
LOG.fine("could not save sample key");
return false;
}
} else {
encryption.freshKeyring(false);
while (true) {
try {
if (new String(encryption.decrypt(ciphertext)).startsWith(SAMPLE_KEY)) {
LOG.fine("succeeded in decrypting sample key");
return true;
} else {
LOG.fine("wrong result decrypting sample key");
}
} catch (Exception x) {
LOG.log(Level.FINE, "failed to decrypt sample key", x);
}
if (!encryption.decryptionFailed()) {
LOG.fine("sample key decryption failed");
return promptToDelete(prefs);
}
LOG.fine("will retry decryption of sample key");
}
}
}
示例4: enabled
import java.util.prefs.Preferences; //導入方法依賴的package包/類
public @Override boolean enabled() {
if (Boolean.getBoolean("netbeans.keyring.no.master")) {
LOG.fine("master password encryption disabled");
return false;
}
if (GraphicsEnvironment.isHeadless()) {
LOG.fine("disabling master password encryption in headless mode");
return false;
}
try {
KEY_FACTORY = SecretKeyFactory.getInstance(ENCRYPTION_ALGORITHM);
encrypt = Cipher.getInstance(ENCRYPTION_ALGORITHM);
decrypt = Cipher.getInstance(ENCRYPTION_ALGORITHM);
Preferences prefs = NbPreferences.forModule(Keyring.class);
Utils.goMinusR(prefs);
String saltKey = "salt"; // NOI18N
byte[] salt = prefs.getByteArray(saltKey, null);
if (salt == null) {
salt = new byte[36];
new SecureRandom().nextBytes(salt);
prefs.putByteArray(saltKey, salt);
}
PARAM_SPEC = new PBEParameterSpec(salt, 20);
LOG.warning("Falling back to master password encryption; " +
"add -J-Dorg.netbeans.modules.keyring.level=0 to netbeans.conf to see why native keyrings could not be loaded");
return true;
} catch (Exception x) {
LOG.log(Level.INFO, "Cannot initialize security using " + ENCRYPTION_ALGORITHM, x);
return false;
}
}