本文整理汇总了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;
}
}