Codota Logo
java.security
Code IndexAdd Codota to your IDE (free)

How to use java.security

Best Java code snippets using java.security (Showing top 20 results out of 35,595)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
SimpleDateFormat s =
  • Codota IconString pattern;new SimpleDateFormat(pattern)
  • Codota IconString template;Locale locale;new SimpleDateFormat(template, locale)
  • Codota Iconnew SimpleDateFormat()
  • Smart code suggestions by Codota
}
origin: alibaba/druid

public static byte[][] genKeyPairBytes(int keySize)
    throws NoSuchAlgorithmException, NoSuchProviderException {
  byte[][] keyPairBytes = new byte[2][];
  KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
  gen.initialize(keySize, new SecureRandom());
  KeyPair pair = gen.generateKeyPair();
  keyPairBytes[0] = pair.getPrivate().getEncoded();
  keyPairBytes[1] = pair.getPublic().getEncoded();
  return keyPairBytes;
}
origin: google/guava

private static boolean supportsClone(MessageDigest digest) {
 try {
  digest.clone();
  return true;
 } catch (CloneNotSupportedException e) {
  return false;
 }
}
origin: stackoverflow.com

 MessageDigest md = MessageDigest.getInstance("MD5");
try (InputStream is = Files.newInputStream(Paths.get("file.txt"));
   DigestInputStream dis = new DigestInputStream(is, md)) 
{
 /* Read decorated stream (dis) to EOF as normal... */
}
byte[] digest = md.digest();
origin: stackoverflow.com

 import java.security.*;

..

byte[] bytesOfMessage = yourString.getBytes("UTF-8");

MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigest = md.digest(bytesOfMessage);
origin: netty/netty

public static InetAddress[] allAddressesByName(final String hostname) throws UnknownHostException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<InetAddress[]>() {
      @Override
      public InetAddress[] run() throws UnknownHostException {
        return InetAddress.getAllByName(hostname);
      }
    });
  } catch (PrivilegedActionException e) {
    throw (UnknownHostException) e.getCause();
  }
}
origin: square/okhttp

 private KeyPair generateKeyPair() {
  try {
   KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(keyAlgorithm);
   keyPairGenerator.initialize(keySize, new SecureRandom());
   return keyPairGenerator.generateKeyPair();
  } catch (GeneralSecurityException e) {
   throw new AssertionError(e);
  }
 }
}
origin: spring-projects/spring-framework

public static ProtectionDomain getProtectionDomain(final Class source) {
  if (source == null) {
    return null;
  }
  return (ProtectionDomain) AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {
      return source.getProtectionDomain();
    }
  });
}
origin: stackoverflow.com

 import java.security.SecureRandom;
import java.math.BigInteger;

public final class SessionIdentifierGenerator {
 private SecureRandom random = new SecureRandom();

 public String nextSessionId() {
  return new BigInteger(130, random).toString(32);
 }
}
origin: spring-projects/spring-framework

/**
 * Return the security context for this bean factory. If a security manager
 * is set, interaction with the user code will be executed using the privileged
 * of the security context returned by this method.
 * @see AccessController#getContext()
 */
protected AccessControlContext getAccessControlContext() {
  return AccessController.getContext();
}
origin: spring-projects/spring-framework

  @Override
  public void checkPermission(Permission perm) {
    // Disallowing access to System#getenv means that our
    // ReadOnlySystemAttributesMap will come into play.
    if ("getenv.*".equals(perm.getName())) {
      throw new AccessControlException("Accessing the system environment is disallowed");
    }
  }
};
origin: spring-projects/spring-framework

@Override
public void checkPropertiesAccess() {
  throw new AccessControlException("Not Allowed");
}
@Override
origin: netty/netty

public static SocketChannel accept(final ServerSocketChannel serverSocketChannel) throws IOException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<SocketChannel>() {
      @Override
      public SocketChannel run() throws IOException {
        return serverSocketChannel.accept();
      }
    });
  } catch (PrivilegedActionException e) {
    throw (IOException) e.getCause();
  }
}
origin: spring-projects/spring-framework

@Override
public AccessControlContext getAccessControlContext() {
  return (this.acc != null ? this.acc : AccessController.getContext());
}
origin: spring-projects/spring-framework

@Override
public void checkPropertiesAccess() {
  // see http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#getProperties()
  throw new AccessControlException("Accessing the system properties is disallowed");
}
@Override
origin: netty/netty

public static InetAddress addressByName(final String hostname) throws UnknownHostException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<InetAddress>() {
      @Override
      public InetAddress run() throws UnknownHostException {
        return InetAddress.getByName(hostname);
      }
    });
  } catch (PrivilegedActionException e) {
    throw (UnknownHostException) e.getCause();
  }
}
origin: netty/netty

public static void bind(final SocketChannel socketChannel, final SocketAddress address) throws IOException {
  try {
    AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws IOException {
        socketChannel.bind(address);
        return null;
      }
    });
  } catch (PrivilegedActionException e) {
    throw (IOException) e.getCause();
  }
}
origin: netty/netty

public static void bind(final DatagramChannel networkChannel, final SocketAddress address) throws IOException {
  try {
    AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws IOException {
        networkChannel.bind(address);
        return null;
      }
    });
  } catch (PrivilegedActionException e) {
    throw (IOException) e.getCause();
  }
}
origin: netty/netty

public static boolean connect(final SocketChannel socketChannel, final SocketAddress remoteAddress)
    throws IOException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
      @Override
      public Boolean run() throws IOException {
        return socketChannel.connect(remoteAddress);
      }
    });
  } catch (PrivilegedActionException e) {
    throw (IOException) e.getCause();
  }
}
origin: netty/netty

  public static byte[] hardwareAddressFromNetworkInterface(final NetworkInterface intf) throws SocketException {
    try {
      return AccessController.doPrivileged(new PrivilegedExceptionAction<byte[]>() {
        @Override
        public byte[] run() throws SocketException {
          return intf.getHardwareAddress();
        }
      });
    } catch (PrivilegedActionException e) {
      throw (SocketException) e.getCause();
    }
  }
}
origin: netty/netty

public static void bind(final Socket socket, final SocketAddress bindpoint) throws IOException {
  try {
    AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws IOException {
        socket.bind(bindpoint);
        return null;
      }
    });
  } catch (PrivilegedActionException e) {
    throw (IOException) e.getCause();
  }
}
java.security

Most used classes

  • MessageDigest
  • SecureRandom
  • AccessController
  • KeyStore
  • Principal
  • NoSuchAlgorithmException,
  • ProtectionDomain,
  • CodeSource,
  • PrivilegedActionException,
  • CertificateFactory,
  • KeyFactory,
  • KeyPair,
  • Security,
  • KeyPairGenerator,
  • Signature,
  • GeneralSecurityException,
  • PublicKey,
  • CertificateException,
  • Certificate
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now